How to increase session lifetime in Laravel
In this tutorial, I will show you How to increase session lifetime in Laravel. Laravel session can not set lifetime session permanently, but we can set in minutes for the session expiration time. If you want to increase your session lifetime, then you need to change the .env file. it is very easy to change it from the configuration file in Laravel. Laravel default provides you session.php file there we can see the lifetime key for setting time in minutes. so we will set 1 year time for the session to expire.
Syntax
Minute * Hours * Days
Example
60 * 24 * 365 = 5,25,600 // 1 year
Solution 1: Using .env File
We need to define value in minutes in your .env file Like:
#.env
SESSION_LIFETIME=525600
And change session.php
<?php
#config/session.php
use Illuminate\Support\Str;
return [
'lifetime' => env('SESSION_LIFETIME', 120),
]
Solution 2: Using session.php File
Direct set session.php file.
<?php
#config/session.php
use Illuminate\Support\Str;
return [
'lifetime' => 1 * (60 * 24 * 365),
]
Sometimes we increase session time but it has not changed, so we need to clear the cache.