I have 3 tables describing users, roles and role_user. They 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 goal here is, of course, to allow the user to have multiple roles.
I can execute a query like User::with('roles')->get() , which works fine.
However, I only want to select users who have a specific role, ideally given by name, but if necessary it can be by identifier. How to do it with Eloquent?
eloquent laravel laravel-4
Rich bradshaw
source share