Laravel - force logout of specific user by user id
I use laravel 5.2.
I want to know how i can force user to logout by id.
I'm building panel admin with the option to dis-active specific user that are currently logged in to the web application
laravel give you the next option for Auth user
Auth::logout()
But i don't want to logout the Auth user. i'm the Auth user. I want to force logout a specific user by is id
like when we login user with specific id
I think the easiest way is to add a column to your users table, for example active and then create a middleware that checks if the user account is active. If it's not active, you log them out and/or redirect them to a page with more info.
I did this in one of my projects, where I would redirect inactive users to a suspended page with some basic information and also contact information.
@Cronix In my case was i have a Connection Monitoring module to list all the login users, if ever the admin wish to disconnect the user I passed the id through AJAX into my controller then i will logout the specific user... But i will try your logic if it's workings...Thanks.
Yes, Auth::user() is the current user. I was saying to put it in middleware. Then, when the user with id of 1 (per my example) accesses the app and they are logged in, it will log them out.
So if you added an is_active column on your users table, the admin can send an ajax request and set that column to a 0 for that user. Then when the user access any route that is using your custom middleware, it would log them out if you had this for your middleware:
if ( ! Auth::user()->is_active) {
Auth::logout();
redirect('/somewhere/else');
}