I have done this: https://shouts.dev/articles/how-to-get-online-users-in-laravel
and it works fine.
But I want to get rid of the users that logs out. Otherwise the list will be too large.
This is my lines for log out:
<li>
<a ui-sref="auth.logout">
<img src="/img/loader-blue.gif" class="img-responsive pull-left margin-top-2 margin-right-4 hide" ng-class="{'show': loadingState == 'auth.logout'}" width="17" height="17">
<i class="fa fa-power-off" ng-class="{'hide': loadingState == 'auth.logout'}"></i> {{_('Log out')}}
</a>
</li>
So, here somewhere here I want to "NULL" the column "last_seen" in my users table when the user logs out.
How?
4
Answers
So with help from Roberto Braga I got it to work with this code in UserController:
Users disappears after two minutes from the list when not active and reappears when activity rises. Great!
Add users model $fillable = [‘last_seen’,…];
In the logout part of your controller, just update the column to null before logging out the user.
But I think this does not solve your issue, since the user usually just close browser without doing logout.
If you want to show just people on-line, according to the code people actively browsing your site in the last 2 minute (see the Middleware), just filter in the query in UserController.
You can try this: