I have 3 models:
Post
, Like
, Trending
The like and trending models are polymorphs, both are:
public function likeable()
{
return $this->morphTo();
}
public function trendingable()
{
return $this->morphTo();
}
When I populate the trendings table based on the likes the only way to access the "posts" from a trending collection is to make a foreach loop like this:
$chart = Trending::all();
foreach($chart as $chartItem)
{
$chartItem->trendingable->title
}
How can I convert the $chart
collection into posts
collection without the foreach loop? I am using Laravel 5.8