I have 3 tables describing users, roles and role_user. These look like this:
users -> id, name
roles -> id, name
role_user -> user_id, role_id
In my User class I have:
public function roles()
{
return $this->belongsToMany('Role');
}
The aim here is of course to allow a user to have multiple roles.
I can do a query like User::with('roles')->get() which works fine.
What I want though is only to select users that have a certain role, ideally specified by name, but it could be by ID instead if needed. How do I do this using Eloquent?