logout a user by another user(admin) in laravel 5.2

后端 未结 1 1137
长情又很酷
长情又很酷 2021-01-16 11:33

lets say three user is currently logged from three device. one of the user(Admin) want to forcely logout user2 , how can it be achieved in laravel 5.2 ??

Database ta

相关标签:
1条回答
  • 2021-01-16 12:32

    The answer that Alexey Mezenin gave is correct. People are not looking at the other user perspective. Auth will return the current user information.

    So for example, User1 wants to log user2 out, User1 clicks on a href link that will log the user2 out. When this link is clicked, $usersId will contain the id of user2. Now the function will be called when the link is being redirect to the route. Auth refers to the current session. But when user2 is login and his id belongs to the $usersID, his account will be logout.

    if(Auth::check() && if (in_array(Auth()->id(), $usersId)) {
      Auth::logout()
    }
    
    0 讨论(0)
提交回复
热议问题