Hi,
You could use the following custom method:
public function scopetagOf($query, $tagname)
{
return $query->whereTag($tagname)->count();
}
You later could call it using:
$laravelCountTags = Tag::tagOf('Laravel');
Hope it helps you.
codeATbusiness said:
Hi,
You could use the following custom method:
public function scopetagOf($query, $tagname) { return $query->whereTag($tagname)->count(); }
You later could call it using:
$laravelCountTags = Tag::tagOf('Laravel');
Hope it helps you.
Thank you but I made mistake while passing tags to the view. I should read data from pivot table. Do you have any idea how to read all tags from pivot table and show their number of occurrences? Pivot table contains tag_id and post_id. I know how to count all occurrences of tag_id but I also need the name of tag which is in another table.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community