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']]);
|
||||
|
||||
@@ -31,6 +31,7 @@ if (!Capsule::schema()->hasTable('products')) {
|
||||
$table->string('variantCode');
|
||||
$table->string('modelCode');
|
||||
$table->string('url');
|
||||
$table->boolean('starred')->default(false);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
* @property string $variantCode
|
||||
* @property string $modelCode
|
||||
* @property string $url
|
||||
* @property boolean $starred
|
||||
*/
|
||||
class Product extends Model
|
||||
{
|
||||
@@ -29,6 +30,12 @@ class Product extends Model
|
||||
return $this->hasMany(Price::class);
|
||||
}
|
||||
|
||||
public function toggleStarred(): self
|
||||
{
|
||||
$this->starred = !$this->starred;
|
||||
return $this;
|
||||
}
|
||||
|
||||
protected function categories(): Attribute
|
||||
{
|
||||
return Attribute::make(
|
||||
|
||||
@@ -4,18 +4,19 @@
|
||||
<table class='table table-hover'>
|
||||
{% for product in products %}
|
||||
<tr>
|
||||
<td class="align-middle font-weight-bold h3"><a class="text-warning text-decoration-none" href="?star={{ product.id }}">{% if product.starred %}★{% else %} ☆ {% endif %}</a></td>
|
||||
<td><img src='{{ product.image }}&width=70' class='img-fluid' alt='{{ product.name }}'/></td>
|
||||
<td><a href='?product_id={{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td>{{ product.subTitle }}</td>
|
||||
<td>
|
||||
<td class="align-middle"><a href='?product_id={{ product.id }}'>{{ product.name }}</a></td>
|
||||
<td class="align-middle">{{ product.subTitle }}</td>
|
||||
<td class="align-middle">
|
||||
<ul class='nav'>
|
||||
{% for category in product.categories %}
|
||||
<li class="nav-item"><a class="nav-link" href="?category={{ category }}"> {{ category }} </a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</td>
|
||||
<td><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||
<td>{{ product.price.last.price }}</td>
|
||||
<td class="align-middle"><a href='https://pl.ryobitools.eu/{{ product.url }}'>link</a></td>
|
||||
<td class="align-middle">{{ product.price.last.price }}</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</table>
|
||||
|
||||
Reference in New Issue
Block a user