• 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

Warning file_get_contents () failed to open stream: HTTP request failed! HTTP/1.0 402 Payment Required

Laravel phpunit test failing authorization

merge all files in directory to one text file

How to make a foreign key not using primary key

PHP: How to raise number to (tiny) fractional exponent?

Clear javascript source cache laravel 5.8

Symfony/Form add attribute based on the data

PHP Download MP3 files from directory on server

PHP my timezone is no setting up in PHP.ini File in xampp

Insert And Retrieve Data in MySQL with $.post Noob Question

add_action() function in wordpress not working [duplicate]

Limit login attempts in Laravel 5.7

error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure

how to youtube api data to print in toolset metabox using a button click before save-post

How to add a custom field to all Woocommerce attribute terms using add_action

About Contact Privacy policy Terms and conditions