我正在与Laravel合作并使用Zizaco Entrust.
以管理员身份登录时,我希望查看特定用户的所有角色.
我搜索了一段时间,但没有找到任何线索......我怎样才能使用Entrust或者我会使用SQL查询?
在您的User类中添加
public function roles()
{
return $this->belongsToMany('Role','assigned_roles');
}
Run Code Online (Sandbox Code Playgroud)
然后,您可以获取特定用户的所有角色
$user = User::with('roles')->find(1);
$roles = $user->roles;
Run Code Online (Sandbox Code Playgroud)