• Categories
    • PHP
    • phpMyAdmin
    • PHPMailer
    • FFMpeg
    • PHPEXcel
    • PHPDoc
    • PHPUnit
    • CakePHP
    • CakePHP 2.0
    • Cake PHP 2.1
    • CakePHP Model
    • Facebook PHP SDK
    • composer-php
    • PHP 7
    • PHP GD
    All Categories
  • About

OctoberCMS / Anonymous Global Scope

phplaraveloctobercmsoctobercms-plugins


PHP Snippet 1:

class PluginModel extends Model
{
    /**
     * Scope a query to only records with user.
     */
    public function scopeGetUserRecords($query, $userId)
    {
        return $query->where('user_id', $userId);
    }
}

PHP Snippet 2:

$userRecords = PluginModel::getUserRecords($user->id)->get();

PHP Snippet 3:

protected static function boot()
{
  parent::boot();

  $user = Auth::getUser();
  static::addGlobalScope('user', function ($query) use ($user) {
    $query->where('user_id', $user->id);
  });
}

Related Snippets

How to make Canonicals with PHP

virtctl works when executed via command line but not from php exec()

Eloquent insert id with sequence next value

How to get monthly wise data in laravel

Display the default discounted price and percentage on Woocommerce products

Is it possible to change the table name in the migration file-laravel

Laravel-fopen: failed to open stream: Permission denied

Can I write PHP code across multiple lines per statement?

How to use a PHP MVC Controller, one thats invoked by calling a URL, to call and execute more than one function? [duplicate]

Dropzone: Submit both form data and dropzone at once

how to display a view on laravel 8 and not have a 404 NOT FOUND page?

Laravel unique validation on multiple columns

PHP: Calling MySQL Stored Procedure with Both INPUT AND OUTPUT Parameters (NOT "INOUT")

Detect a fetch request in PHP

How to generate QR CODE for dynamic generating link and logo using Simple QrCode in laravel?

About Contact Privacy policy Terms and conditions