[英]Laravel voyager policy based on user role
I can't find out how to determine user role in voyager. 我无法确定如何确定航行者中的用户角色。 I am trying to do some policy check based on user role like this:
我正在尝试根据这样的用户角色进行一些策略检查:
public function browse(User $user)
{
$user->role == 'admin';
}
But this returns false ( This action is unauthorized.
) even for user with role admin. 但是,即使对于具有角色admin的用户,
This action is unauthorized.
返回false( This action is unauthorized.
)。 I am using laravel 5.6 and voyager 1.1.3 我正在使用laravel 5.6和voyager 1.1.3
There is no role or role_name in users table in voyager. voyager的用户表中没有任何角色或角色名。 I have to use role_id
我必须使用role_id
public function browse(User $user)
{
if ( $user->role_id == 1 ) {
return true;
} else {
return false;
}
}
Is there any way I can use role name? 有什么方法可以使用角色名称?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.