I'm working in this Laravel project which has this structure
users: id | first_name |...
roles: id | name
assigned_roles: id | user_id | role_id
I think this is quite obvious :p
User model
class User extends ConfideUser {
use HasRole;
public function Roles(){
return $this->belongsToMany('Role','assigned_roles');
}
Role model
class Role extends EntrustRole
{
public function Users()
{
return $this->belongsToMany('User','assigned_roles');
}
}
I'm looking for a way to get all users with a specified role in this case 'Teacher'. I've tried this:
$students = User::with(array('Roles' => function($query) {
$query->where('name','Teacher');
}))
->get();
return $students;
but this always returns an array of all users.
would anyone know why that's so? Thanks!