Laravel Set or Increase Session Lifetime

Hello Artisan, today I'll talk about how you can set or increase the session lifetime in Laravel. Laravel provides us default session timeout of 2 hours. But sometimes we need to extend it. So, lets' see how we can increase the session timeout in our application.

Note: Tested on Laravel 9.2.

AS we know Laravel framework is also known as for highly customizable. So we can simply change the session timeout without any headache. By simply modify our .env file we can achieve it. If we look our .env file we can find a variable named SESSION_LIFETIME which is set to 120 like below

SESSION_LIFETIME=120

So here 120 means 2 hours because the timeout count as a minutes

60 * 2 = 120

So, if you want to increase our session lifetime for the next one week then our value will be

60 * 24 * 7  = 10080

We can also change the session lifetime through our session.php. We just need to update our below variable

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

Just update the value of lifetime like below

 'lifetime' => 10080

And it's done.

That's it for today. Hope you'll enjoy through this tutorial. Thanks for reading :)