Duane Blake

Front end developer

How to set a user session time in Laravel

By default Laravel when logging a user into a website the session time is set to 120 minutes. They may be instances where you need this increased. As with most things in Laravel Its straight forward to do.

How to set a user session time in Laravel

The way to increase this we need to add or edit the environment variable called SESSION_LIFETIME to our .env file. But lets first look at where this variable is referencing.

If you open the following file config/session.php and look for the line below.

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

The number is set in minutes as you can see this is 120 minutes, you can either update it here or I suggest adding it into your .env file.

Open your .env file and either add in the below or change the existing value in my example I want it set to a day which is 24 hours. So that would be 1440 (60*24). So the value would be 1440.

SESSION_LIFETIME=1440

As you can see its straight forward to update the value of session time just update the number in your .env file

Leave a comment

Your email address will not be published.