Laravel [↗] by default logs out an inactive user after some minutes. For apps that are the main drivers of a person's business, you might want to avoid requiring the user to log in every few minutes.
Laravel allows you to choose how long all sessions last, and since the login state of a user is stored as a session we can increase the default session time to increase how long a user is logged in for.
By increasing the session time to a very large number, the user will be logged in for a very long time for example 200 years ツ.
You might however want to decrease this time down to say 30 days, this way you can ensure the user logs in at least once a month as a security measure.
Follow the steps below to increase the session time:
- From your Laraval project open up your
.env
file. - Look for the
SESSION_LIFETIME
variable, if it's not yet available, you can go ahead and add it. - Set the value of the variable to the duration you will like your sessions to last, thus how long a user should be logged in for. This value is in minutes, for example, setting it to
43200
means the user will be logged in for 30 days.
This variable is used to set the lifetime
value in the config/session.php
config file.
Here is another article you might like 😊 "Knowing When It's A Model Or A Builder(Laravel)"