Skip to content

Commit a22a79d

Browse files
committed
Convert breadcrumb list items to a plain array before encoding
spatie/schema-org's serializeProperty() only recurses into PHP arrays, so the Laravel Collection passed to itemListElement() got coerced via __toString() into a JSON string. That left BreadcrumbList with a stringified itemListElement and per-item @context, which Search Console flagged as invalid (#215). Calling ->all() lets serializeProperty recurse normally and strip the nested @context.
1 parent 8ba6d12 commit a22a79d

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/Cascades/ContentCascade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,8 @@ public function breadcrumbs(): ?string
233233
->map(fn ($crumb) => Schema::listItem()
234234
->position($crumb['position'])
235235
->name($crumb['title'])
236-
->item($crumb['url']));
236+
->item($crumb['url']))
237+
->all();
237238

238239
return json_encode(
239240
Schema::breadcrumbList()->itemListElement($listItems),

tests/Cascades/ContentCascadeTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,14 @@
332332

333333
$breadcrumbs = json_decode($this->cascade->breadcrumbs(), true);
334334

335-
expect($breadcrumbs['@type'])->toBe('BreadcrumbList');
335+
expect($breadcrumbs['@context'])->toBe('https://schema.org')
336+
->and($breadcrumbs['@type'])->toBe('BreadcrumbList')
337+
->and($breadcrumbs['itemListElement'])->toBeArray();
338+
339+
foreach ($breadcrumbs['itemListElement'] as $item) {
340+
expect($item)->not->toHaveKey('@context')
341+
->and($item['@type'])->toBe('ListItem');
342+
}
336343
});
337344

338345
it('returns null page schema when json ld is not set', function () {

0 commit comments

Comments
 (0)