@trh88 you can append conditionals when attempting to log-in a user. The following paragraph and code is taken directly from the documentation.
If you wish, you also may add extra conditions to the authentication query in addition to the user's e-mail and password. For example, we may verify that user is marked as "active":
if (Auth::attempt(['email' => $email, 'password' => $password, 'active' => 1])) {
// The user is active, not suspended, and exists.
}
You could also override the protected function credentials(Request $request) method from the AuthenticatesUsers trait in the Laravel-generated LoginController :
This doesn't seem to be taken into account when clicking on login on the default laravel auth pages, it logs in again even though I have set the active field to 0 in the database for the user...
I found another solution for this situation. My case requires separate message for blocked users. So I can't use provided approaches, because users will get message that credentials are wrong. It can be confusing.
There is an authenticated() method which will be called after credential are checked. Inside you can perform any checks for additional conditions on $user. And if something is wrong - logout user and provide specific message.
Auth/LoginController.php
protected function authenticated(Request $request, $user)
{
if ($user->status !== 1) {
Auth::logout();
return redirect(route('login'))->withErrors(['common' => trans('auth.blocked')]);
}
}