kaizokupuffball
2 weeks ago

Laravel relationship issue.

Posted 2 weeks ago by kaizokupuffball

I have three tables "users", "roles" and "role_users". The user table does not have any role_id field. So mapping of user with role is maintained in "role_users" table by having role_id and user_id fields.

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.

Please sign in or create an account to participate in this conversation.