mercredi 15 novembre 2017

Have a Laravel model have a relationship with 2 different models

My setup so far is a customer contact portal, and there is an Organization, Contact and Note models. A Contact belongs to an Organization, and an Organization has many Contacts. I have no problems with that, however I am having an issue trying to tie the Notes model to be able to have a relationship with both the Organization and Contact. Basically so I can leave a Note on an Organization but also leave another note on the Contact, and be able to search for Notes that belong to a given Contact or Organization.

I first thought of a pivot table that stored the ids of the models as well as the model type. Which I think is the same as a polymorphic pivot table? However I have not played with that yet, and not sure where to start.

Is the pivot table the way to do it? Or is there an easier way so I don't have additional tables all in my database?



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

Aucun commentaire:

Enregistrer un commentaire