mardi 1 août 2017

Laravel. morphToMany in cascade mode

I am looking a way of doing the following:

Let's say we have a Theater application and we have three Models: Event, Session and Seat on one hand and Rate on the other hand.

We have a morphToMany relation so a Rate can be associated with any of the other three models.

Now, we want to have a rates() relation in each model that work in kind a cascade mode. If we ask for rates() on a Seat instance it will returns its Rates if the have, otherwise, it will check if the Session does have Rates and will return them. If not, it will return the Rates associated with Event.

So we want to define like a hierachy or cascade mode to retrieve Rates.

How would you do this??

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire