Reputation: 4663
Can we set expire time for each session in Laravel?
If we can, how is it possible from the controller for each session that we create?
Upvotes: 9
Views: 58372
Reputation: 287
Change the SESSION_LIFETIME= (duration in minutes)
in the environment configuration.
Upvotes: 3
Reputation: 13083
You can change the session lifetime, application wide by changing the lifetime
value on config/session.php
:
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 4320,
'expire_on_close' => false,
Now, if you want to control the session lifetime per user, you need to set this value before logging in the user.
- Try if user exists in database
- If yes, and he is user who needs longer session lifetime, run
config(['session.lifetime' => $newLifetime]);
- Log user in
- Enjoy longer session lifetime for current user
— Source
You have to make the above changes in LoginController
.
Upvotes: 29