mercredi 26 juin 2019

Complex relationships with Eloquent/Laravel

Same story as many other questions on this site: I've banged my head into the wall for hours on end trying to figure out these relationships.

I have 3 models where the relationship should work like this:

Model: User
User can belong to many schools.
User belongs to one “Role” separately on each school.
User can be activated/deactivated separately on each school.

Model: School.
School can belong to many users

Model: Role.
Roles would be “Standard” or “Administrator”


I want to access data like this:

User
Get schools belonging to the user.
Get role for current school.
Get activated/deactivated status for current school.

School
Get all users belonging to the school.
Get role for each user.
Get activated/deactived status for each user.


I would've solved this if users could only belong to one school each, but since the same user can belong to several schools it got too complicated for me.

What kind of relationships should I apply on each model?

I would very much appreciate if anyone can point me in the right direction here. Thanks!



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2xkCftr
via IFTTT

Aucun commentaire:

Enregistrer un commentaire