Display big category tree on route /category/ without parameter

This commit is contained in:
2026-01-27 08:56:54 +01:00
parent 62c6538b89
commit 9f368a266a
2 changed files with 86 additions and 71 deletions

View File

@@ -8,8 +8,8 @@ use Symfony\Component\Routing\Attribute\Route;
final class CategoryController extends BaseController
{
#[Route('/category/{category}', name: 'app_category')]
public function __invoke(string $category): Response
#[Route('/category/{category?}', name: 'app_category', defaults: ["category" => null])]
public function __invoke(?string $category): Response
{
if($this->cache->getItem('list_category_'.$category)->isHit()) {
return $this->render('productList.html.twig', ['listType' => 'category_'.$category]);
@@ -19,8 +19,8 @@ final class CategoryController extends BaseController
$products = Product::with(['price', 'lowestPrice'])
->selectRaw('products.*')
->distinct('products.id')
->when(!is_null($category) , fn ($q) => $q->whereRaw('json_each.value = ?', [$category]))
->fromRaw('products, json_each(products.categories)')
->whereRaw('json_each.value = ?', [$category])
->orderByDesc('starred')
->orderByDesc('created_by')
->get();