I have a Laravel project in which there is likely to be multiple many to many relationships but I feel like I'm going around in circles in terms of the correct use of pivots tables.
The entities are as follows:
Considerations:
The bottom statement is where I'm going in circles because:
This is because a user can't be directly assigned to a task, they can only be assigned to a task within a centre as the tasks have a many to many relationship with centres.
If I were to assign a user just using task id, they would be assigned to that task in every related centre.
So, again is it okay to have a pivot table that uses another pivot table, or does this display an issue with the structure I have suggested?
Intended flow
In theory I'd end up with a pivot table that has the following:
Essentially I just feel like I'm connecting too many pieces?
Laravel does the linking for you, simply use (in this case) morphToMany()
& morphedByMany()
in your Models to establish a relation between two tables. There is a very good Laracast and also a very good Documentation. I have linked this below:
Laracast Video very nice Explaination for Many-To-Many Relations
Laravel Documentation for Eloquent ORM In General
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.