I need to fire events when a user initializes a session under Laravel, when he closes it or when the lifetime of said session expires. The reason why I need to do this is that I have to identify from a Control Panel, which users have an active session on the site. Reviewing in other posts, it is suggested to use events and from there this implementation idea arises, but if you have implemented this in another way or Laravel itself already has some magic command that can be used, I will be very grateful for the data. I apologize for not providing code for your review as I haven't started yet and am still reviewing alternatives.
Thank you very much in advance and best regards.
Well I did this (there must be better ways I know) with the Laravel cache.
First you have to create a middleware in my case LastUserActity and in the handle
in my case I only give it a minute to live and every time the user reloads a page it is recreated
You register it in the kernel.php middlewareGroups
and in your users model add the following
and now if you want to know if a user is online you just have to do
To obtain the list, you could do the following:
I hope it helps