问题
I've created an anonimus global scope in the users model as below in order to get only public users in the frontend:
protected static function boot()
{
parent::boot();
static::addGlobalScope('is_public', function(Builder $builder) {
$builder->where('is_public', '=', 1);
});
}
But... when i need to perform the login in the backend i need of course to check for not-public users so i need to exclude the global scope.
Is this possibile using the default AuthController of laravel?
Many Thanks!!
回答1:
You just need to create two Models - one without global scope (i.e. AuthUser) and another with the global scope that extends the first one (i.e. User).
Then you can use AuthUser for authentication And User everywhere else.
回答2:
You can remove any global scope on the fly with the following method:
User::withoutGlobalScope('is_public')->get();
来源:https://stackoverflow.com/questions/34696134/laravel-global-scope-auth