How To Increase Session Lifetime In Laravel

In this small tutorial I will show you how to increase session timeout in laravel, in this example we can see how to set session lifetime in laravel.

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
  • 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.

Read Also : How To Create Dynamic Pie Chart In Laravel

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

Solution 1: Using .env File

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

.env

SESSION_LIFETIME=525600

config/session.php

<?php

use Illuminate\Support\Str;

return [

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

]

Solution 2: Using Config File

config/session.php

<?php

use Illuminate\Support\Str;

return [

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

]

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

For clearing Cache, View, Routes in Laravel check below.

Read Also : Laravel Clear Cache Using Artisan Command

And, Now your session timeout time will be increased...

Read Also : Bootstrap Session Timeout Example In Laravel