Hello.
In my app user model has a global scope "active", which checks if the "active" column in the users table equals 1. If the user decides to disable an account (not delete), then this column changes to 0 and user will not be in scope. The idea is that inactive user should be able to login back and his account will automatically be enabled.
Here is the code in User model to add "active" scope:
protected static function boot() {
parent::boot();
static::addGlobalScope('active', function(Builder $builder) {
$builder->where('active', 1);
});
}
The problem is now inactive users can't log in back again, because AuthController ignores them. I am using the provided AuthController (php artisan make:auth).
Is there any way to remove the scope only for authentication process? Maybe with events?... My skills in Laravel are not yet so good.
Thanks.
You may have to manually handle the auth, but you can remove the scope easily with withoutGlobalScopes:
elite123 said:
You may have to manually handle the auth, but you can remove the scope easily with withoutGlobalScopes:
Removing global scope during auth would be the best for me, but I didn't find where it should be removed for auth only :(
Hi I've the same problem. Someone can help me with some code to better understand how to do it? thanks
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community