多角色登录的授权策略为什么验证一直失败?
1.现在有两种角色:学生和教师,我分别在config/auth.php
中注册了guards和providers
目前可以在通过Auth::gurad('stu')和Auth::guard('tec')来执行有关权限的相关操作(如验证是否登录、获取当前登录用户信息)
2.我通过php artisan make:policy StuPolicy --model=Student
创建了一个关于学生操作的授权策略,并在AuthServiceProvider.php
中注册了
StuPolicy.php中的update方法:
但当我在学生的资源控制器中的edit方法调用$this->authorize('upload',$stu)
时,全部用户都无权访问修改信息页面(包括当前登录用户自己),控制器方法:
public function edit( Student $stu ) {
$this->authorize( $stu );
return view( 'stu.pages.edit', compact( 'stu' ) );
}
请问这是为什么?是我授权策略编写不正确还是因为我的权限管理编写不正确呢?希望各位能够帮助我
试试
$this->authorizeForUser(Auth::guard('student')->user(), 'update', $student);