我有一个users表,并使用spatie/laravel-permission包。我需要一个管理员能够登录作为一个不同的用户暂时,并看到该网站作为该用户的观点。管理员在临时以其他用户身份登录时不应注销。有没有办法在Laravel中做这样的事情?
发布于 2019-11-25 17:46:00
是的,你绝对可以在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.有关更多用法,请查看文档
如果您对软件包不感兴趣,请查看以下链接:
https://pineco.de/impersonating-users/
https://mauricius.dev/easily-impersonate-any-user-in-a-laravel-application/
https://laracasts.com/discuss/channels/general-discussion/impersonating-users
如果有isue,请注解
https://stackoverflow.com/questions/59028799
复制相似问题