Laravel doc provides polymorphic "many-to-many" sample (pivot table taggables) with the following structure:
taggables
tag_id - integer
taggable_id - integer
taggable_type - string
Here only one side is polymorphic (taggable_*). My case is:
- "instances" model family contains "field", "event" etc
- "templates" model family contains "template_field", "template_event" etc
- pivot table structure is:
template_registry:
id
instance_type - string
instance_id - integer
template_type - string
template_id - integer
Which PHP code required to get something like:
$field->template
where template get linked template object (template_field / template_event)