• 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

Phalcon: setStatusCode returns empty response

Respond with status code 401 on authentication failure using Laravel and Passport?

Laravel Displaying image from database

How to get monthly wise data in laravel

How to validate Envato Purchase Code in PHP

Laravel phpunit test failing authorization

Laravel whole batch is cancelled if one Job fails

How to convert the int value to inch in PHP [closed]

Cross-Origin Resource Sharing (CORS) witth Laravel and Vuejs

Add a text next to stock quantity if it is less than 10 in Woocommerce single product

The sum of the user's points

Google Calendar API batch request PHP

Laravel with App Engine Standard Class 'FacadeIgnitionIgnitionServiceProvider' not found

Insert database rows from columns of data from associative array of indexed arrays

PHP random string generator

About Contact Privacy policy Terms and conditions