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

Hamelraj's avatar

How to genearte session using Auth::loginUsingId(); ?

after using Auth::loginUsingId(); how to use another route with same user details ? EX :

Route::get('a',function(){
    $user = Auth::loginUsingId(1, true);
    dd($user);
});
Route::get('b',function(){
    $user = Auth::user();
    dd($user);
});

after a route when i check b route $user is null ????

0 likes
7 replies
Snapey's avatar

try with dump() instead of dd. with dd you break the request cycle and I think this stops the session being saved (or something like that)

Snapey's avatar

so, you no longer use dd()?

sounds like session is not saving. There are numerous threads about that on the forum, but with no common cause it seems.

Check your Storage/framework/session folder and see if a session is being created

Hamelraj's avatar

no i used dump now .....session folder its creating session but when i try to get auth::user() im getting null

Snapey's avatar
Snapey
Best Answer
Level 122

sorry for all the questions but your code is fine. The only thing I would change is to just return $user at the end of each test.

are you running route a and route b in the same browser tab?

1 like

Please or to participate in this conversation.