Laravel set or increase session lifetime example tutorial. Here, you will learn how to set the session timeout or session lifetime in your laravel web applications.
This tutorial will help you to how to set session timeout in laravel web applications.
Note that, you can not set session timeout for forever. But you can set easily session in your laravel web application.
Here, if you want to set session timeout for 1 year in your laravel web application. You can do the following:
60 * 24 * 365 = 525600
Note that, you can set session timeout only in minutes. Like above.
Here, you will learn two ways to set session life or session timeout for your laravel web application.
: First Way – Using .env File
First of all, Go to your project root directory and find .env file. After that, open .env file and set session timeout like following:
.env
SESSION_LIFETIME=525600
When you set the timeout of the session in the .env file. So the config folder has a session.php. In this file, the session timeout of your laravel web application is set in this way.
<?php
use Illuminate\Support\Str;
return [
.....
'lifetime' => env('SESSION_LIFETIME', 120),
.....
]
2: Second Way – Using Config File
In the first way, you saw that the session timeout or session lifetime was first set in the .env file and then it was gated from the .env file, then set the session timeout in the session.php.
In this step, you will learn how to set session timeout or session lifetime in config/session.php file.
So open your config/session.php file and set session timeout like following:
<?php
use Illuminate\Support\Str;
return [
.....
'lifetime' => 1 * (60 * 24 * 365),
.....
]
Conclusion
In this post, you have learned two ways to set session timeout or session lifetime for laravel web applications.