Bozboz
4 years ago

Eloquent's morphedByMany method

Posted 4 years ago by Bozboz

As far as I can tell, unlike with one-to-many polymorphic relations using morphMany/morphTo, there is no way to retrieve all of a polymorphic relation when using many-to-many polymorphic relationships (morphToMany/morphedByMany).

To take the example in the docs (http://laravel.com/docs/5.1/eloquent-relationships#many-to-many-polymorphic-relations), posts and videos must be retrieved separately from a Tag. Why is it not possible to implement a taggable method that retrieves all taggable types associated with that Tag, which would result in a collection of Video and Post instances? As far as I can tell, it would operate in a similar way to the morphTo method, however it would need to retrieve the taggable_type and taggable_id attributes from the pivot table.

Am I missing something here for why this isn't possible, or is this just unimplemented functionality?

Please sign in or create an account to participate in this conversation.