laravel 委托 - 获取角色所在的所有用户

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22730759/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 09:16:44  来源:igfitidea点击:

Entrust - Get all users where role is

laravellaravel-4eloquentroles

提问by

I have a role where the user must be 'approved' first, before accessing certain parts of the site. The role ID for 'unapproved' is 5, approved is 2.

我有一个角色,在访问网站的某些部分之前,用户必须首先获得“批准”。“未批准”的角色 ID 为 5,已批准为 2。

Within my admin view, I want to get all users where role ID = 5, to then be able to delete/approve etc...

在我的管理员视图中,我希望获得角色 ID = 5 的所有用户,然后才能删除/批准等...

Currently, my admin controller is:

目前,我的管理员控制器是:

public function getUnApproved()
{

    $role = Role::find(5)->user()->get();

    $this->layout->content = View::make('admin.manage.approve', 
                                         array('role' => $role));
}

The error message is:

错误信息是:

BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::user()

BadMethodCallException 调用未定义的方法 Illuminate\Database\Query\Builder::user()

Entrust is set up correctly, with a Role, Permission model. My user model 'HasRole' also.

Entrust 设置正确,具有 Role、Permission 模型。我的用户模型也是“HasRole”。

Any help would be hugely appreciated.

任何帮助将不胜感激。

回答by

By making plural 'user', this solved my problem.

通过制作复数“用户”,这解决了我的问题。

$role = Role::find(5)->users()->get();