Laravel 如何同时以其他用户身份登录

Laravel 如何同时以其他用户身份登录,laravel,authentication,admin,Laravel,Authentication,Admin,我有一个用户表,使用spatie/laravel权限包。我需要一个管理员能够登录临时作为一个不同的用户,并看到该用户的观点网站。管理员在以其他用户身份临时登录时不应注销。在Laravel中有这样做的方法吗?是的,在Laravel中你绝对可以这样做。为此,您需要安装软件包 //here 10 indicates the user id and you can change this $otherUser = User::find(10); Auth::user()->impersonat

我有一个用户表,使用spatie/laravel权限包。我需要一个管理员能够登录临时作为一个不同的用户,并看到该用户的观点网站。管理员在以其他用户身份临时登录时不应注销。在Laravel中有这样做的方法吗?

是的,在Laravel中你绝对可以这样做。为此,您需要安装软件包

//here 10 indicates the user id and you can change this

$otherUser = User::find(10);

Auth::user()->impersonate($other_user);
//now you are logged in as the user id with 10

//to stop impersonating

Auth::user()->leaveImpersonation();

// You're now logged as your original user.

下面是这个包的一些基本用法

//here 10 indicates the user id and you can change this

$otherUser = User::find(10);

Auth::user()->impersonate($other_user);
//now you are logged in as the user id with 10

//to stop impersonating

Auth::user()->leaveImpersonation();

// You're now logged as your original user.
如需了解更多用法,请查看文档

如果您对软件包不感兴趣,请查看以下链接:


注释如果有iSUE

除非您有两个不同的会话管理器,分别用于
管理员
用户
,否则您不能同时以两个用户的身份登录。您应该“登录”该用户,但作为管理员,您可以授予自己查看其他配置文件的权限。我不知道这个软件包。如果我的回答能解决问题,请接受我的回答谢谢你的回复,但我需要同时在管理面板和用户面板中工作的能力。当模拟用户管理会话关闭时,我得到403。你知道吗?如果你需要以管理员身份登录,那么你需要注销登录的用户。或者你必须使用多重防护。供认证