addConnection(['driver' => 'sqlite', 'database' => __DIR__ . '/database.sqlite']); $capsule->setAsGlobal(); $capsule->bootEloquent(); $loader = new FilesystemLoader(__DIR__ . '/src/templates'); $twig = new Environment($loader); if (isset($_GET['product_id'])) { $template = 'product.html.twig'; $product = Product::with('price')->find($_GET['product_id']); } if (isset($_GET['category'])) { $template = 'productList.html.twig'; $products = Product::with('price')->selectRaw('products.*')->fromRaw('products, json_each(products.categories)')->whereRaw('json_each.value = ?', [$_GET['category']])->get(); } if (isset($_GET['search'])) { $template = 'productList.html.twig'; $products = Product::with('price') ->orWhere([['name', 'like', "%{$_GET['search']}%"]]) ->orWhere([['subTitle', 'like', "%{$_GET['search']}%"]])->get(); } if (empty($_GET)) { $template = 'productList.html.twig'; $products = Product::with('price')->get(); } $twig->display($template, ['products' => $products, 'product' => $product, 'search' => $_GET['search']]);