• 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 Command Schedule Not Working Properly

Update Order custom Field value with WooCommerce REST API

Center point of multiple gps coordinates with php

How to give apache permission to write to home directory?

Parameter is not sent to Laravel route in Ajax

Laravel MSSQL Server Connection not working

How to run a shell as root from php (apache)

WordPress Subquery returns more than 1 row on SELECT

retrieve data from database using session

Error Class "LaravelFortifyFeatures" not found

Laravel dosen't connect with Oracle

Laravel Gates using model and returns "Using $this when not in object context" Line 28 of AzureUser model

Fetch files from next cloud storage and display in Laravel website

Detect emoticons in string

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

About Contact Privacy policy Terms and conditions