• 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

Laravel display validation error

Undefined Array Key error when uploading image on php

Woocommerce Edit Message "An account is already registered with your email address. Please log in."

Center point of multiple gps coordinates with php

Symfony Mercure "Failed to send an update"

Why is this PHP array not the same?

Laravel 8 factory state afterCreating

how to retrieve the first and last instance of a row in pdo dataset

Docker image build with PHP zip extension shows "bundled libzip is deprecated" warning

Search for array row with specific column value and return another value from qualifying row

TesseractOCR not working for Laravel

Issue with laravel eloquent model property

Laravel phpunit test failing authorization

How to set time with DateTime modify?

I'm trying to use curl with php but getting this error:Could not resolve host: Bearer

About Contact Privacy policy Terms and conditions