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

+1 -4
View File
@@ -20,10 +20,7 @@
<div class="flex items-end justify-between gap-x-6 gap-y-3 flex-wrap mb-10 lg:mb-16">
<h1 class="font-medium text-h2">{{ $collection['name'] }}</h1>
<x-breadcrumb :items="[
['label' => __('storefront.nav.home'), 'href' => route('home')],
['label' => $collection['name']],
]" />
<x-breadcrumb :items="$breadcrumb" />
</div>
{{-- Everything that reflects sort / filter / page state lives in this
@@ -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)
+1 -6
View File
@@ -6,12 +6,7 @@
@section('content')
<div class="max-w-7xl mx-auto px-5 sm:px-8 py-12">
<x-breadcrumb class="mb-8 justify-end lg:mb-14" :items="[
$collection
? ['label' => $collection['name'], 'href' => route('category.show', ['id' => $collection['id']])]
: ['label' => __('storefront.nav.products'), 'href' => route('products')],
['label' => $product['name']],
]" />
<x-breadcrumb class="mb-8 justify-end lg:mb-14" :items="$breadcrumb" />
<div
class="grid grid-cols-1 md:grid-cols-2 gap-12"
-1
View File
@@ -19,7 +19,6 @@
<h1 class="font-medium text-h2">{{ __('storefront.shop.all_products') }}</h1>
<x-breadcrumb :items="[
['label' => __('storefront.nav.home'), 'href' => route('home')],
['label' => __('storefront.shop.all_products')],
]" />
</div>
+1 -2
View File
@@ -19,8 +19,7 @@
<h1 class="font-medium text-h2">{{ $heading }}</h1>
<x-breadcrumb :items="[
['label' => __('storefront.nav.home'), 'href' => route('home')],
['label' => __('storefront.search.results_for') . $heading],
['label' => __('storefront.search.results_for') . ' ' . $heading],
]" />
</div>