Files
3dealer/resources/views/components/breadcrumb.blade.php
T

57 lines
2.1 KiB
PHP
Raw Normal View History

2026-07-31 17:41:55 +03:00
@props(['items' => []])
{{--
$items: array of ['label' => string, 'href' => string|null]
Home is always prepended here, so pages pass only their own trail.
2026-07-31 17:41:55 +03:00
Last item is the current page — no link, no href needed.
Example:
<x-breadcrumb :items="[
['label' => 'Jackets', 'href' => route('category.show', ['id' => 12])],
2026-07-31 17:41:55 +03:00
['label' => 'Leather Jacket'],
]" />
Also pushes matching BreadcrumbList JSON-LD to the layout's `seo` stack.
2026-07-31 17:41:55 +03:00
--}}
@php
// Untranslated collection names can arrive empty; skip them rather than
// render an empty crumb.
$items = array_values(array_filter([
['label' => __('storefront.nav.home'), 'href' => route('home')],
...$items,
], fn ($item) => filled($item['label'] ?? null)));
@endphp
@push('seo')
<script type="application/ld+json">
{!! json_encode([
'@@context' => 'https://schema.org', {{-- @@ escapes Blade's @context directive --}}
'@type' => 'BreadcrumbList',
'itemListElement' => collect($items)->map(fn ($item, $index) => array_filter([
'@type' => 'ListItem',
'position' => $index + 1,
'name' => $item['label'],
'item' => $item['href'] ?? null,
], fn ($value) => $value !== null))->values()->all(),
], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_HEX_TAG) !!}
</script>
@endpush
2026-07-31 17:41:55 +03:00
<nav aria-label="Breadcrumb">
<ol {{ $attributes->merge(['class' => 'flex items-center flex-wrap gap-1 text-base text-black']) }}>
@foreach ($items as $index => $item)
<li class="flex items-center gap-1">
@if (!$loop->first)
<span aria-hidden="true">/</span>
@endif
@if (!empty($item['href']))
<a href="{{ $item['href'] }}" class="underline-slide [--slide-h:1px]">{{ $item['label'] }}</a>
@else
<span class="pb-1" aria-current="page">{{ $item['label'] }}</span>
@endif
</li>
@endforeach
</ol>
</nav>