donkfather
3 years ago
207
4
Laravel

many to many to many

Posted 3 years ago by donkfather

Hello to all,

I have a big dilema. I have to entities that have a many to many relationship. But the pivot table has a many to many with another entity.

for example:

Users       Roles       user_role           Tags
#id         #id         #user_id            #id
                        #role_id
                        other data

The user_role has a many to many with tags. Have can I do this with Eloquent ? Should I create another Model for user_role ? If I do

$user->roles()->attach($role)

I need the that to return the id or somehow get the id and based on that I need to add tags to that relation.

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