Closed timgavin closed 5 years ago
Tags are just regular Eloquent models, so you can query them directly. See https://laravel.com/docs/5.8/eloquent-relationships#counting-related-models
Something like this would probably work (untested):
$tags = Tag::withCount('taggedModels')->get();
In your controller
$tags = Post::allTagsList();
In your views
@foreach ($tags as $name => $count) {
{{ $name }} // Get the tag name
{{ $count }}// Get the count value
}
@endforeach
Hope this helps :)
$tags = Tag::withCount('taggedModels')->get();
Call to undefined method Cviebrock\EloquentTaggable\Models\Tag::taggedModels()
$tags = Post::allTagsList(); dd($tags);
"tag1,tag2,...,tag100500"
Both methods do not give results.
You are right: neither of those options work.
However, getPopularTags
just does a count on the tags, so this should give you what you want:
$tags = app(TagService::class)
->getPopularTags(null, null, 0)
->pluck('taggable_count', 'normalized')
->toArray();
Is there a way to display all tags (not popular tags, but ALL tags) with a count of how many times they have been used?