I have three tables "users", "roles" and "role_users". Apparently, user table does not have any role_id field. Therefore mapping of user with role is maintained in "role_users" table by having role_id and user_id fields.
What association i will need to write in both models User and Role to fetch a list of all users of a particular role e.g.'teacher'?
Here is what i am currently doing in User model:
public function teachers() {
return $this->has_many('Role')->where('name','teacher');
}
This is not working, but i could not understand that how would i make the relationship in this model.