Added a way to starr a product, so it floats on top of the list of products
This commit is contained in:
10
browser.php
10
browser.php
@@ -18,7 +18,8 @@ if (isset($_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();
|
||||
$products = Product::with('price')->selectRaw('products.*')->fromRaw('products, json_each(products.categories)')->whereRaw('json_each.value = ?', [$_GET['category']])
|
||||
->orderByDesc('starred')->orderByDesc('created_by')->get();
|
||||
}
|
||||
if (isset($_GET['search'])) {
|
||||
$template = 'productList.html.twig';
|
||||
@@ -26,9 +27,12 @@ if (isset($_GET['search'])) {
|
||||
->orWhere([['name', 'like', "%{$_GET['search']}%"]])
|
||||
->orWhere([['subTitle', 'like', "%{$_GET['search']}%"]])->get();
|
||||
}
|
||||
if (isset($_GET['star'])) {
|
||||
Product::find($_GET['star'])->toggleStarred()->save();
|
||||
header('Location: '.$_SERVER['HTTP_REFERER']);
|
||||
}
|
||||
if (empty($_GET)) {
|
||||
$template = 'productList.html.twig';
|
||||
$products = Product::with('price')->get();
|
||||
$products = Product::with('price')->orderByDesc('starred')->orderByDesc('created_by')->get();
|
||||
}
|
||||
|
||||
$twig->display($template, ['products' => $products, 'product' => $product, 'search' => $_GET['search']]);
|
||||
|
||||
Reference in New Issue
Block a user