I am working on a project with many-to-many relationship between two tables roles
and users
. I also have a pivot table role_user
that holds information about the relation between the other two tables.
role_user
two fields namely the id
s of the two tables: role_id
and user_id
.
Now I have a user object gotten from the users
table and another role object gotten from the roles
table. I want to determine if a particular role belongs to a certain user.
I know this can be done by creating a model for the pivot table and then using the model, the role_user
table can be queried and determined if the relation exists.
But I find this method stressful and wonder if eloquent provides an easy method to determine this.
Thanks for any help?