handle route detail product if slug null

This commit is contained in:
Bayu Lukman Yusuf 2026-03-04 13:59:11 +07:00
parent 79a2bf7fce
commit b609c648a8
5 changed files with 9 additions and 9 deletions

View File

@ -57,7 +57,7 @@ class SearchController extends Controller
'number' => $product->number, 'number' => $product->number,
'slug' => $product->slug ?? $product->id, 'slug' => $product->slug ?? $product->id,
'type' => 'product', 'type' => 'product',
'route' => route('product.detail', $product->slug) 'route' => $product->slug != null ? route('product.detail', $product->slug) : '',
]; ];
}); });
} }

View File

@ -56,7 +56,7 @@
aria-label="Add to Wishlist"> aria-label="Add to Wishlist">
<i class="ci-heart animate-target"></i> <i class="ci-heart animate-target"></i>
</button> --}} </button> --}}
<a class="d-block" href="{{ route('product.detail', [$value->slug]) }}"> <a class="d-block" href="{{ $value->slug != null ? route('product.detail', [$value->slug]) : '#' }}">
<div class="ratio" style="--cz-aspect-ratio: calc(191 / 191 * 100%)"> <div class="ratio" style="--cz-aspect-ratio: calc(191 / 191 * 100%)">
<img src="{{ $value->image_url }}" alt="Image" loading="lazy"> <img src="{{ $value->image_url }}" alt="Image" loading="lazy">
</div> </div>
@ -86,7 +86,7 @@
<div class="h6 mb-2">{{ $value->display_price_currency }}</div> <div class="h6 mb-2">{{ $value->display_price_currency }}</div>
<h3 class="fs-sm lh-base mb-0"> <h3 class="fs-sm lh-base mb-0">
<a class="hover-effect-underline fw-normal" <a class="hover-effect-underline fw-normal"
href="{{ route('product.detail', [$value->slug]) }}">{{ $value->name }}</a> href="{{ $value->slug != null ? route('product.detail', [$value->slug]) : '#' }}">{{ $value->name }}</a>
</h3> </h3>
</div> </div>
@if ($value->variants->count() > 1) @if ($value->variants->count() > 1)

View File

@ -69,7 +69,7 @@
aria-label="Add to Wishlist"> aria-label="Add to Wishlist">
<i class="ci-heart animate-target"></i> <i class="ci-heart animate-target"></i>
</button> --}} </button> --}}
<a class="d-block" href="{{ route('product.detail', $value->slug) }}"> <a class="d-block" href="{{ $value->slug != null ? route('product.detail', $value->slug) : '#' }}">
<div class="ratio" style="--cz-aspect-ratio: calc(191 / 191 * 100%)"> <div class="ratio" style="--cz-aspect-ratio: calc(191 / 191 * 100%)">
<img src="{{ $value->image_url }}" alt="Image"> <img src="{{ $value->image_url }}" alt="Image">
</div> </div>
@ -99,7 +99,7 @@
<div class="h6 mb-2">{{ $value->display_price_currency }}</div> <div class="h6 mb-2">{{ $value->display_price_currency }}</div>
<h3 class="fs-sm lh-base mb-0"> <h3 class="fs-sm lh-base mb-0">
<a class="hover-effect-underline fw-normal" <a class="hover-effect-underline fw-normal"
href="{{ route('product.detail', $value->slug) }}">{{ $value->name }}</a> href="{{ $value->slug != null ? route('product.detail', $value->slug) : '#' }}">{{ $value->name }}</a>
</h3> </h3>
</div> </div>
@if ($value->variants->count() > 1) @if ($value->variants->count() > 1)

View File

@ -11,7 +11,7 @@
aria-label="Add to Wishlist"> aria-label="Add to Wishlist">
<i class="ci-heart animate-target"></i> <i class="ci-heart animate-target"></i>
</button> </button>
<a class="d-flex bg-body-tertiary rounded" href="{{ route('product.detail', $product->slug ?? $product->id ?? '0') }}"> <a class="d-flex bg-body-tertiary rounded" href="{{ $product->slug != null ? route('product.detail', $product->slug) : '#' }}">
<div class="ratio" style="--cz-aspect-ratio: calc(308 / 274 * 100%)"> <div class="ratio" style="--cz-aspect-ratio: calc(308 / 274 * 100%)">
<img src="{{ $product->image_url }}" loading="lazy" class="w-100 h-100 object-cover"> <img src="{{ $product->image_url }}" loading="lazy" class="w-100 h-100 object-cover">
</div> </div>
@ -19,7 +19,7 @@
</div> </div>
<div class="nav mb-2"> <div class="nav mb-2">
<a class="nav-link animate-target min-w-0 text-dark-emphasis p-0" <a class="nav-link animate-target min-w-0 text-dark-emphasis p-0"
href="{{ route('product.detail', $product->slug ?? $product->id ?? '0') }}"> href="{{ $product->slug != null ? route('product.detail', $product->slug) : '#' }}">
<span class="text-truncate">{{ $product->name ?? '' }}</span> <span class="text-truncate">{{ $product->name ?? '' }}</span>
</a> </a>
</div> </div>

View File

@ -25,14 +25,14 @@
@if($order && $order->details) @if($order && $order->details)
@foreach ($order->details as $detail) @foreach ($order->details as $detail)
<div class="d-flex align-items-center"> <div class="d-flex align-items-center">
<a class="flex-shrink-0" href="{{ route('product.detail', $detail->reference->item->slug ?? '#') }}"> <a class="flex-shrink-0" href="{{ $detail->reference->item->slug != null ? route('product.detail', $detail->reference->item->slug) : '#' }}">
<img src="{{ $detail->reference->item->image_url ?? '/img/shop/electronics/thumbs/01.png' }}" <img src="{{ $detail->reference->item->image_url ?? '/img/shop/electronics/thumbs/01.png' }}"
width="110" alt="{{ $detail->reference->item->name ?? 'Product' }}"> width="110" alt="{{ $detail->reference->item->name ?? 'Product' }}">
</a> </a>
<div class="w-100 min-w-0 ps-2 ps-sm-3"> <div class="w-100 min-w-0 ps-2 ps-sm-3">
<h5 class="d-flex animate-underline mb-2"> <h5 class="d-flex animate-underline mb-2">
<a class="d-block fs-sm fw-medium text-truncate animate-target" <a class="d-block fs-sm fw-medium text-truncate animate-target"
href="{{ route('product.detail', $detail->reference->item->slug ?? '#') }}"> href="{{ $detail->reference->item->slug != null ? route('product.detail', $detail->reference->item->slug) : '#' }}">
{{ $detail->reference->item->name ?? 'Product Name' }} {{ $detail->reference->item->name ?? 'Product Name' }}
</a> </a>
</h5> </h5>