PetrKaterinak
1 month ago
257
3
Laravel

Laravel 7 - LoginController - allow only users with "active=1"

Posted 1 month ago by PetrKaterinak

Hi there, I searched over the internet and almost all answers went to https://laravel.com/docs/7.x/authentication#authenticating-users . So I used it. In database I have a few testing users with extra column "active". Only one of them have active = 1.

By the Laravel manual I've added this to the LoginController:

public function authenticate(Request $request)
    {
        if (Auth::attempt(['email' => $request->email, 'password' => $request->password, 'active' => 1], $request->remember)) {
            return redirect('/admin');
        }
    }

But I'm still able to login as user, which have active = 0. What is wrong with my code?

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