Structured data (JSON-LD)
toJsonLd() builds a schema.org BlogPosting (or Article) array for the current locale from data the post already has; renderJsonLd() wraps it in a <script type="application/ld+json"> element through the posts::json-ld view. Configure the type, author attribute and publisher:
'json-ld' => [
'type' => 'BlogPosting', // or 'Article'
'author-attribute' => 'name', // read from the author model
'publisher' => [
'name' => env('POSTS_PUBLISHER_NAME'),
'logo' => env('POSTS_PUBLISHER_LOGO'),
],
],$post->toJsonLd();
// [
// '@context' => 'https://schema.org',
// '@type' => 'BlogPosting',
// 'headline' => 'Hello world',
// 'description' => 'A short summary',
// 'image' => 'https://example.com/cover.png',
// 'datePublished' => '2026-01-01T12:00:00+00:00',
// 'dateModified' => '2026-01-02T09:30:00+00:00',
// 'author' => ['@type' => 'Person', 'name' => 'Jane Doe'],
// 'publisher' => [
// '@type' => 'Organization',
// 'name' => 'Example Ltd',
// 'logo' => ['@type' => 'ImageObject', 'url' => 'https://example.com/logo.png'],
// ],
// 'mainEntityOfPage' => ['@type' => 'WebPage', '@id' => 'https://example.com/posts/hello-world'],
// 'keywords' => ['eloquent', 'php'],
// 'articleSection' => ['Guides', 'Laravel'],
// ]
$post->renderJsonLd(); // HtmlString: <script type="application/ld+json">{…}</script>Where each key comes from
| Key | Source |
|---|---|
@context / @type | https://schema.org and json-ld.type |
headline | the title with the same locale fallback as $post->title and the meta tags |
description | seo()->metaDescription, or '' |
image | seo()->ogImage — explicit og:image, else the featured image; omitted when empty |
datePublished / dateModified | published_at / updated_at, ISO-8601 |
author | Person named by the author’s json-ld.author-attribute; omitted without an author or name |
publisher | Organization from json-ld.publisher.name (+ logo as ImageObject); omitted without a name |
mainEntityOfPage | WebPage with the canonical URL as @id — only when a canonical is set |
keywords | the post’s tag names in the current locale, with locale fallback |
articleSection | the post’s category names in the current locale, with locale fallback |
Safe output
renderJsonLd() hex-escapes <, >, &, ' and " inside the JSON (JSON_HEX_TAG, JSON_HEX_AMP, JSON_HEX_APOS, JSON_HEX_QUOT), so a title, perex, author, tag or category name containing </script> cannot break out of the script element. If you published posts-views from an earlier version, re-publish json-ld.blade.php or apply the same flags to your copy.
Show your open-source love
This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.
More ways to support, including cryptoBy donating, you agree to our donation terms.
Want this built into your product?
We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.