I noticed a bug in my application when a user logs into my site from multiple computers, they are displayed twice in the list of logged in. I managed to fix this by adding the groupBy('user_id') to my query, however I noticed something else wrong now: the user's last active field only updates for 1 of them.
return $query->whereNotNull('user_id')->with('user')->groupBy('user_id')->get();
To make this a bit clearer, prior to adding groupBy, lets say a user Bob logged in at 2 locations. My logged in users would look like this:
Bob Last Active 1 hour ago, Bob Last Active 6 minutes ago
However, with the groupBy, it might show this:
Bob Last Active 1 hour ago
Even though the latest activity is 6 mintues ago. I tried running a sortBy('last_activity'), however both ascending and descending have failed to fix this issue. Does anyone have any ideas?
Thanks.