• 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

Call authenticate manually in router middleware

Must be of the type array, null given,

How to reset Laravel AuthManager/guards in between API calls in tests?

Facebook SDK error: Cross-site request forgery validation failed. Required param "state" missing from persistent data

Laravel display validation error

how to remove %20 in the url in php

The "client_reference_id" argument is not passed

Is there a way to use the same parameter into multiple place in the same query with Eloquent? [duplicate]

Substitute integers and dots with regex [duplicate]

Detect a fetch request in PHP

How to pass security cloudflare server with php curl

Uncaught TypeError: Cannot read property 'length' of null when retrieving tags from wp

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

Cannot retrieve error message using Symfony HttpClient if the response is not "ok"

auth pages not getting css in laravel

About Contact Privacy policy Terms and conditions