Breadcrumbs: always start at Home, full category trail, BreadcrumbList JSON-LD

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
elviraandClaude Opus 5.5 committed 2026-10-27 12:19:29 +02:00
1 parent 9d7f92ebfc
commit fb239a97cb
8 files changed
+114 -18

No files matched your search

@@ -2,15 +2,42 @@
{{--
$items: array of ['label' => string, 'href' => string|null]
Home is always prepended here, so pages pass only their own trail.
Last item is the current page — no link, no href needed.
Example:
<x-breadcrumb :items="[
['label' => 'Jackets', 'href' => '/category/jackets'],
['label' => 'Jackets', 'href' => route('category.show', ['id' => 12])],
['label' => 'Leather Jacket'],
]" />
Also pushes matching BreadcrumbList JSON-LD to the layout's `seo` stack.
--}}
@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
<nav aria-label="Breadcrumb">
<ol {{ $attributes->merge(['class' => 'flex items-center flex-wrap gap-1 text-base text-black']) }}>
@foreach ($items as $index => $item)