• 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

Entity provider not working in security.yml php symfony3.4 ({"code":401,"message":"bad credentials"}.)

How to get company posts from LinkedIn via API?

Composer Curl error 60: SSL certificate problem: unable to get local issuer certificate

Adding multiple items to WooCommerce cart at once

Yii2: How do I debug console commands?

I want to store data in new index as per my key in php [duplicate]

Move a child array to parent array and change parent/child name

Pass a select with mysqli_fetch_row to a table

Limit of log line written to Apache Errorlog from mod php error_log

PHPUNIT Test - Expected Status 200 But Received 500

PHP returning an error message and false

How to delete old images from public folder on update using Laravel

Call authenticate manually in router middleware

I want to use codeigniter foreign character library in my custom PHP project how i can use it?

Laravel after login Two factor not working

About Contact Privacy policy Terms and conditions