Support the ongoing development of Laravel.io →
Authentication

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.

Last updated 3 years ago.
0

Hello! Did you find a way?

0

You may have to manually handle the auth, but you can remove the scope easily with withoutGlobalScopes:

https://laravel.com/docs/5.3/eloquent#global-scopes

0

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 :(

0

Hi I've the same problem. Someone can help me with some code to better understand how to do it? thanks

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

BrakaTakl brakatakl Joined 16 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.