In my project I am using session destroy method which very simple way in Laravel 5.2 .
/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/
'lifetime' => 10,
'expire_on_close' => true,
Now my question is when session destroy automatically or user close browser tab or close browser that time execute logout query. Is it possible execute logout function all cases?
My logout function
public function logout()
{
$user = Auth::user()->toArray();
$user1 = ActiveUsers::where("assinedto_id",'=',$user['_id']);
$user1 ->delete();
Auth::logout();
return redirect('/login');
}
I want to when session destroy or close browser tab or close browser that time run logout()
function. Please suggest me. Thanks
The server does not know if the user has closed the browser window. You need to detect this event via javascript on the client side and notify the server manually.
See this answer: javascript detect browser close tab/close browser