Support the ongoing development of Laravel.io →
Requests Eloquent Views
Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

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.

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

alenn-m alenn-m Joined 5 Mar 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.