Laravel-如何获得特定用户的委托角色 [英] Laravel - How to get Entrust Roles of a specific user
本文介绍了Laravel-如何获得特定用户的委托角色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在与Laravel合作,并使用 Zizaco Entrust .
I'm making a small work with Laravel and using Zizaco Entrust.
以管理员身份登录时,我想查看特定用户的所有角色.
While logged in as Administrator I want to see all Roles of a specific user.
我搜索了一段时间,但没有发现任何线索... 如何使用 Entrust 进行操作,还是应该使用SQL查询?
I'v searched for a while but didn't find any clue... How can I do it using Entrust or shall I use SQL queries?
推荐答案
在您的User类中添加
In your User class add
public function roles()
{
return $this->belongsToMany('Role','assigned_roles');
}
然后,您可以获取特定用户的所有角色
Then you can get all roles for a specific user
$user = User::with('roles')->find(1);
$roles = $user->roles;
这篇关于Laravel-如何获得特定用户的委托角色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文