Laravel Global Scope Auth

I created a global anonimus scope in the user model, as shown below, to get only public users in the interface:

protected static function boot()
{
    parent::boot();

    static::addGlobalScope('is_public', function(Builder $builder) {
        $builder->where('is_public', '=', 1);
    });
}

But ... when I need to login to the backend, of course, I need to check non-public users, so I need to exclude the global scope.

Is this possible using the default AuthController for laravel?

Many thanks!

+3
source share
1 answer

You just need to create two Models - one without a global scope (i.e. AuthUser), and the other with a global scope that extends the first (i.e. the user).

Then you can use AuthUser for authentication and user everywhere.

+4

All Articles