Login if user is active using Laravel Breeze
PHP Snippet 1:
Auth::attempt($this->only('email', 'password') + ['active' => 1]) ...
PHP Snippet 2:
if (Auth::attempt([...], $remember_me)) {
if (Auth::user()->is_active == 1) {
user-will-stay-login
}
else{
User::logout();
return \redirect()->back();
}
}
PHP Snippet 3:
public function authenticate()
{
$this->ensureIsNotRateLimited();
if (Auth::attempt($this->only('email', 'password'), $this->boolean('remember'),)) {
if (Auth::user()->isActive != 1) {
Auth::logout();
throw ValidationException::withMessages([
'email' => __('auth.suspend'),
]);
}
} else {
RateLimiter::hit($this->throttleKey());
throw ValidationException::withMessages([
'email' => __('auth.failed'),
]);
}
RateLimiter::clear($this->throttleKey());
}
