modify filter calculation
This commit is contained in:
@@ -16,15 +16,19 @@ class TagGroups
|
||||
|
||||
public static function getWithTagsAndCountOffers($category_id = false)
|
||||
{
|
||||
$tags = Tag::withCount(['articles'])->get()->toArray();
|
||||
$tags = Tag::withCount(['articles' => function($query) use ($category_id) {
|
||||
$query->byCategory($category_id);
|
||||
}])->get()->toArray();
|
||||
$tag_groups = TagGroup::pluck('name', 'id')->toArray();
|
||||
foreach ($tags as $tag) {
|
||||
$data[$tag['tag_group_id']]['name'] = $tag_groups[$tag['tag_group_id']];
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
'count' => $tag['articles_count'],
|
||||
];
|
||||
if ($tag['articles_count']) {
|
||||
$data[$tag['tag_group_id']]['tags'][] = [
|
||||
'id' => $tag['id'],
|
||||
'name' => $tag['name'],
|
||||
'count' => $tag['articles_count'],
|
||||
];
|
||||
}
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user