Level 73
What is there to explain, it throws an exception if the auth attempt fails.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
public function store()
{
$attributes = request()->validate([
'email' => 'required|email',
'password' => 'required'
]);
if (! auth()->attempt($attributes)) {
throw ValidationException::withMessages([
'email' => 'Your provided credentials email/password could not be verified.'
]);
}
session()->regenerate();
return redirect('/')->with('success', 'Welcome Back!');
}
there is explanation in docs https://laravel.com/docs/9.x/authentication#authenticating-users
Basically auth::attempt() find user with giving value and session regenerate is to prevent 'session fixation'
Please or to participate in this conversation.