The problem is that I need to do an action the moment a session expires, regardless of whether the browser is open or not.
I have a project in Laravel and it is registered when the user is online or offline, when he logs into the system, it registers in the database 1 for the user who is online, and when he leaves, it registers 0. I want it to register 0 when the session expired without the user needing to refresh the screen. Even if the user closes the browser without logging out, the system will register that the user is offline when the session expires.
My English is not good and this is my first question here on the platform.
Thank you anyway!
2
Answers
liquid207 thanks for replying! I am using
file
as session driverI kept doing some testing and researching further and found this link which discusses this very issue:
Laravel session timeout, extra logout code
In this case, a middleware is used, but if the user closes the browser without exiting, even with the browser closed, will the middleware work?
Method
SessionHandlerInterface::gc()
will be invoke when session expires. You can override this method according to the following steps:I suppose that you use
database
as session driver.DatabaseSessionHandler
, overridegc
IlluminateSessionSessionManager
, overridecreateDatabaseDriver
to return class defined in step 1