Laravel How to Increase/Decrease Session Lifetime

Hello Artisans, today I'll show you how to increase or decrease the session lifetime in our Laravel application. We all know that Laravel provides 2 hours of session lifetime as default. So, in today's tutorial, we'll see two examples of how we can modify the time of session lifetime.

Table of Contents

  1. Example 1
  2. Example 2

Example 1

At first, we'll increase the time from .env file. We just need to modify the time of SESSION_LIFETIME in minutes.

Like if we want to set the time for one year, the .env will look like the below:

.env
 SESSION_LIFETIME=525600 //24*60*365 = 525,600

Example 2

In this example, we'll use session.php to increase/decrease the time of session. Let's see the below code.

config/session.php
<?php

use Illuminate\Support\Str;

return [

		.....
    'lifetime' => 525600,

		.....
];

That's it for today. I hope you've enjoyed this tutorial. Thanks for reading. ๐Ÿ™‚