modify filter calculation

This commit is contained in:
Ludovic CANDELLIER
2022-05-09 22:33:18 +02:00
parent 8c898bf63b
commit 3370b8061c
5 changed files with 43 additions and 27 deletions

View File

@@ -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;
}