Display big category tree on route /category/ without parameter
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user