Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rhynelCast's avatar

Laravel Auth Session not working properly

$user = User::where('email', $email)->first();

\Auth::guard('web')->($user);

It works but when I visited to any website or when I reload the Auth turns to NULL

0 likes
2 replies
tykus's avatar

This gets a Collection of Users, not a single user instance.

$login = User::all();

You would actually need to fetch a single User instance, e.g.

$user = User::findOrFail($id);
// or 
$user = User::where('email', $email)->first();

This next expression is invalid - I assume a typo???

\Auth::guard('web')->($login);

// should be

\Auth::guard('web')->login($user);
1 like
rhynelCast's avatar

Sorry, I mean yah still not working on a single user.

Please or to participate in this conversation.