Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jasonkw9's avatar

Laravel log user details when session timeout

Let's say I set the session lifetime to 15 minutes,so by default, laravel will auto logout the user after session timeout. What I want to do now is to log this action in database saying that this user has been logged out due to session expired.

Can anyone just give me an idea on how to do it?

0 likes
1 reply
willvincent's avatar

You might be able to manage it by adding a listener for the Auth\Logout event, but whether or not you'll be able to differentiate between a session expiration or a manual logout that way is a question.

Your best bet might be to implement a custom session driver that extends whatever session driver you would otherwise use, then override the gc and possibly destroy methods to insert your log entry in the DB.

1 like

Please or to participate in this conversation.