samedi 24 février 2018

Many to many polymoprhic relationship with a single Pivot table in Laravel 5.5

I have the following four models:

  • App\Chain
  • App\Shop
  • App\ProductGroup
  • App\Product

I am wondering if it is possible to use a single pivot table with the following columns in order to store many to many relationships between any of the models:

Table name: owner_entity_child_entity

  • id
  • owner_entity_type (all models, except for chain)
  • owner_entity_id
  • child_entity_type (all models, except for product)
  • child_entity_id

So that when, for example, I query $chain->products, I would be able to retrieve all the products that are not only directly linked to the $chain itself, but also to the shops and product groups that are linked to the chain.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire