dimanche 2 décembre 2018

Laravel Many to Many (3 and 3+ Models) Design Question

I have got three models

Contacts Model Contact Roles Model Project Model Set up;

contacts can belong to multiple projects. (Many to Many) each project has its own contact roles created by user. (One to Many - Roles are specific to projects) Within selected project, a contact can be assigned to multiple roles (Many to many) Tricky part is I have categories for roles model, when user is creating the role, they select a category for that role from a dropdown(from a db, total of 7 predefined categories).

Then what I try to do and have issue with understanding;

1.What is the best way to display all contacts with given roles on that specific project?

I can easily get $project->contacts() //this gives me all contacts within that projectbut I need to one step further, where I can get contacts with their roles.

2.Furthermore, how would I display all contacts that are part of that selected category for that project?

3.Should i be using a different connection between my models other than many to many, like has many through ?



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

Aucun commentaire:

Enregistrer un commentaire