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

rupali's avatar

Laravel session not persisting

I have created session in laravel , but its getting destroyed after long time. I kept a user logged in , didn't shutdown the system but the next day or two the session gets destroyed , when accessing the user profile page its gives error.

Have used the following to save the session :

           $session = new Session();
        $session->user_id = $user->id;
        $session->token = $site_login;
        // save in database
        $session->save();
        return redirect('/home')->withCookie(cookie()->forever('site_login', $site_login));
0 likes
3 replies
cipsas's avatar

You can define how long session should persist in config/session.php file

WebKenth's avatar
'lifetime' => 120,

Default lifetime of a session is 2 hours

you can change it in config/session.php:32

Please or to participate in this conversation.