I want make relationship with attribute but i dont understand how to do that with laravel ORM Eloquent, can somebody help me? Thanks in advance
-
using laravel you cant define a single relation for the 3 entities. What you can do is declare a ManyToMany relation between `Mahasiswa` and `Role` as `roles()` and another ManyToMany relation between `Mahasiswa` and `Team` as `teams()`. – N69S Oct 25 '21 at 08:35
1 Answers
If I'm not mistaken, you want to have a many-to-many relationship between your Mahasiswa
and Team
. Basically, it means that you have many teams, and each teams has its own members, so does members, each member can have teams. So you will need an intermediate/a pivot table between those two, for ex. mahasiswa_team
. Then, inside mahasiswa_team
table, you could add the role
column to define each member's role.
For many-to-many relationship inside Laravel 8, you can see the documentation here.
If many-to-many relationship is not correct, then my last guess is you want the one-to-many relationship between Team
and Mahasiswa
. In that case, you want to move your role
column to the Mahasiswa
table. For one-to-many relationship, you can see the documentation here.

- 362
- 3
- 13