Skip to content

Commit 64cac90

Browse files
committed
Show "No image" image if the product does not have images
1 parent 1124c7a commit 64cac90

File tree

4 files changed

+6
-5
lines changed

4 files changed

+6
-5
lines changed

public/img/noimage.png

58.3 KB
Loading

resources/views/cart/index.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
$products->map(fn($product) => [
99
'id' => $product->id,
1010
'slug' => $product->slug,
11-
'image' => $product->image,
11+
'image' => $product->image ?: '/img/noimage.png',
1212
'title' => $product->title,
1313
'price' => $product->price,
1414
'quantity' => $cartItems[$product->id]['quantity'],

resources/views/product/index.blade.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class="grid gap-8 grig-cols-1 md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 p-5"
2020
x-data="productItem({{ json_encode([
2121
'id' => $product->id,
2222
'slug' => $product->slug,
23-
'image' => $product->image,
23+
'image' => $product->image ?: '/img/noimage.png',
2424
'title' => $product->title,
2525
'price' => $product->price,
2626
'addToCartUrl' => route('cart.add', $product)
@@ -30,7 +30,7 @@ class="border border-1 border-gray-200 rounded-md hover:border-purple-600 transi
3030
<a href="{{ route('product.view', $product->slug) }}"
3131
class="aspect-w-3 aspect-h-2 block overflow-hidden">
3232
<img
33-
src="{{ $product->image }}"
33+
:src="product.image"
3434
alt=""
3535
class="object-cover rounded-lg hover:scale-105 hover:rotate-1 transition-transform"
3636
/>

resources/views/product/view.blade.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div x-data="productItem({{ json_encode([
33
'id' => $product->id,
44
'slug' => $product->slug,
5-
'image' => $product->image,
5+
'image' => $product->image ?: '/img/noimage.png',
66
'title' => $product->title,
77
'price' => $product->price,
88
'quantity' => $product->quantity,
@@ -12,7 +12,8 @@
1212
<div class="lg:col-span-3">
1313
<div
1414
x-data="{
15-
images: {{$product->images->map(fn($im) => $im->url)}},
15+
images: {{$product->images->count() ?
16+
$product->images->map(fn($im) => $im->url) : json_encode(['/img/noimage.png'])}},
1617
activeImage: null,
1718
prev() {
1819
let index = this.images.indexOf(this.activeImage);

0 commit comments

Comments
 (0)