Closed devendragohil closed 6 years ago
@devendragohil did you figured out about this. I am also looking for a similar solution.
@devendragohil I got the solution for it ... read through this documentation its self explanatory https://laravel.com/docs/5.1/eloquent-relationships#polymorphic-relations. I have also post the example below as well.
$data = []; $results = Tagged::where('tag_slug', $slug)->get(); if($results) { foreach ($results as $key => $result) { $data[$key] = $result->taggable; } return $data; }
In above case Tagged Model is linked to the dynamic pivot table, tagging_tagged. The method taggable() in the Tagged Model retrieve the owner of a polymorphic relation from the polymorphic model.
Hope the above will be helpful for you.
Kind regards, Javed Gardezi
I want to retrieve all of the models that at associated with provided tag. Is it possible?
For example, for
Article
model I have created a tagfoo
and also forAuthor
model I have created the same tagfoo
. Now is there any method that providing tag namefoo
will return all the models associated with it i.e.Article
andAuthor
.