0

I am making an internal app for my company that show's who is online. Kind of a clock in, clock out tool. If a user closes their window though, I need my database to be updated to show that they're logged out.

I am still relatively new to Laravel. I know that you can set a session to expire when the user closes the window, which I have set to true. However, I need to be able to update my database when an authenticated user closes their window. I'm not even sure if this is possible. If not, is there a way to simply show all users who are online or offline?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dylan
  • 63
  • 2
  • 9

1 Answers1

0

Check out the following post about detecting window close with javascript:

javascript detect browser close tab/close browser

You could setup a route for decrementing the online users and fire off an AJAX method that hits that route when the onunload or onbeforeunload events fire.

Now, it wouldn't be 100% accurate as those methods also fire when the user leaves the site via a link.

Community
  • 1
  • 1
Christopher Rathgeb
  • 1,677
  • 17
  • 20