• 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

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

How to extract price from given url using Xpath?

How to run or debug php on Visual Studio Code (VSCode)

shell errors running php exec

Form repeater send wrong data with last element in Laravel

Coinpayments create_transaction "ERROR: Invalid command!"

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource [duplicate]

SMTP ERROR: MAIL FROM command failed: 530 5.7.0 Must issue a STARTTLS command first when using PHPMailer

Laravel Blade checkbox not checked

target [LaravelFortifyContractsRegisterViewResponse] is not instantiable

Query Optimization, changing the queries in the loop into a single processing query

Autoloading classes in PHPUnit using Composer and autoload.php

how to insert data into select2 search input after scan using qrcode

PHP array, move keys and values to new array, but mix it up

Getting values for an enum?

About Contact Privacy policy Terms and conditions