ersanserkan
1 week ago
127
5
Laravel

Global Scope for User model

Posted 1 week ago by ersanserkan

Hello! How can I deactivate global scope for authentication only?

I want to hide root type users from queries except authentication..

<?php

namespace App\Scopes;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Scope;

class UserScope implements Scope
{
    /**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param  \Illuminate\Database\Eloquent\Builder  $builder
     * @param  \Illuminate\Database\Eloquent\Model  $model
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        $builder->where('type', '!=', 'root');
    }
}

Please sign in or create an account to participate in this conversation.