嗨我正在使用Laravel和雄辩为了存储用户,有配置文件和那里分配的角色。我的表格结构如下;Laravel 4雄辩的表加入和多个表上的where子句
users
id | username | email | password | created_at | updated_at
profiles
id | user_id | firstname | created_at | updated_at
roles
id | name
assigned_roles
id | user_id | role_id
我试图选择角色名称等于admin的所有用户。但是当我做下面的时候,我得到一个空阵列:
return \User::with('profile')->join('assigned_roles', function ($join) {
$join->where('assigned_roles.user_id', '=', 'users.id');
})->get();
任何想法我做错了什么?
而且我使用Zizaco委托和倾诉https://github.com/Zizaco/entrust/tree/1.0
@trincot no that is correct。我有一个在app/models/User.php中定义关系的函数 – 001221
只是为了确保...您为用户定义了“assigned_roles”中的角色?如果没有相应的行,则不会返回任何结果。 –
@ jedrzej.kurylo我没有这个模型,我使用https://github.com/Zizaco/entrust/tree/1.0,但它没有这样做的功能 – 001221