我的auth.PHP文件看起来像这样
<?PHPreturn [ 'defaults' => [ 'guard' => 'web','passwords' => 'users',],'guards' => [ 'web' => [ 'driver' => 'session','provIDer' => 'users','API' => [ 'driver' => 'token','admin' => [ 'driver' => 'session','provIDer' => 'admins','student' => [ 'driver' => 'session','provIDer' => 'students','finance' => [ 'driver' => 'session','provIDer' => 'finances','admin-API' => [ 'driver' => 'token','finance-API' => [ 'driver' => 'token','provIDers' => [ 'students' => [ 'driver' => 'eloquent','model' => App\student::class,'finances' => [ 'driver' => 'eloquent','model' => App\Finance::class,'admins' => [ 'driver' => 'eloquent','model' => App\users::class,'finance' => [ 'driver' => 'eloquent',// 'users' => [ // 'driver' => 'database',// 'table' => 'users',// ],'passwords' => [ 'students' => [ 'provIDer' => 'students','table' => 'password_resets','expire' => 60,'finances' => [ 'provIDer' => 'finances','admins' => [ 'provIDer' => 'admins','expire' => 15,'finance' => [ 'provIDer' => 'finance',];
我可以检查auth用户,但我们有一些对所有用户都相同的路由和控制器,我需要检查相同路由或控制器中的所有防护,以便登录的每种类型的用户.
如何检查同一控制器或路径中的多个警卫?
解决方法 对于要进行身份验证的每个控制器public function __construct() { $this->mIDdleware('auth:admin,student,finance'); }
要么
你可以在路线上使用
Route::group(['mIDdleware' => 'auth:admin,finance,student'],function () { any same route here});
您可以像这样访问刀片中的用户详细信息
{{ Auth::guard('admin')->user()->name }} {{ Auth::guard('admin')->user()->last_name }}
我希望这可以帮助别人.
总结以上是内存溢出为你收集整理的php – 检查Laravel控制器中的多个警卫全部内容,希望文章能够帮你解决php – 检查Laravel控制器中的多个警卫所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)