DEV Community

Techsolutionstuff
Techsolutionstuff

Posted on • Originally published at techsolutionstuff.com

How To Increase Session Lifetime In Laravel

In this tutorial we will see you how to increase session timeout in Laravel. In this example we can see how to set / increase session lifetime in Laravel 6/7/8.

We can not set lifetime session for permanently but we can set in minutes for session expiration time. so here we will set 1 year time for session expire.

60 * 24 * 365 = 525600 // 1 year
Enter fullscreen mode Exit fullscreen mode

If you want to increase your session life time then we need to change in .env file and it is very easy to change it from configuration file in laravel. laravel provides you session.php file there is we can see 'lifetime' key option for setting time in minutes.

In session configuration file there is a also several option for set expire_on_close, encrypt, timeout and driver etc.

Here I will give you solution for increase session timeout in laravel.

Example 1 : Using .env File

We need to define value in minutes in your .env file as below:

.env

SESSION_LIFETIME=525600
Enter fullscreen mode Exit fullscreen mode

config/session.php

<?php

use Illuminate\Support\Str;

return [

    'lifetime' => env('SESSION_LIFETIME', 120),

]
Enter fullscreen mode Exit fullscreen mode

Example 2 : Using Config File

config/session.php

<?php

use Illuminate\Support\Str;

return [

    'lifetime' => 1 * (60 * 24 * 365),

]
Enter fullscreen mode Exit fullscreen mode

In some conditions also happen cache issue, So, we need to clear it.


You might also like :

Top comments (0)