Example of Global scopes in LaravelDaily/Laravel-Support-Ticketing

File app/Scopes/AgentScope.php (link to Github)
use Illuminate\Database\Eloquent\Scope;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Builder;

class AgentScope implements Scope
{
    public function apply(Builder $builder, Model $model)
    {
        $user = auth()->user();
        if(auth()->check() && request()->is('admin/*') && $user->roles->contains(2))
        {
            $builder->where('assigned_to_user_id', $user->id);
        }
    }
}
File app/Ticket.php (link to Github)
use Illuminate\Database\Eloquent\Model;
use Spatie\MediaLibrary\HasMedia;

class Ticket extends Model implements HasMedia
{
    //
    public static function boot()
    {
        parent::boot();
        //
        static::addGlobalScope(new AgentScope);
    }
    //
}

Additional resources on global scopes: