• 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

Can't call javascript alert alertify library from PHP

Add and update products to session cart in Laravel

best way to store error messages in Laravel (session or variable)

PHPExcel_IOFactory::createWriter causes wrong behaviour

How can I make a full text index of the column?

ConstraintViolationListInterface to Exception in Symfony

How to use React Router with Laravel?

Laravel Delete and Update

SQL AVG() to 2 decimals

Reload parent page after submit in iframe

PHP web3 ERC20 token function call

How can i hide dt if dd got empty value

Laravel You requested 1 items, but there are only 0 items available

carbon generated datetime not stored correctly into the database

How to create laravel storage symbolic link for production or sub domain system?

About Contact Privacy policy Terms and conditions