---
title: "Structured data (JSON-LD) — Posts for Laravel | Roundly"
description: "schema.org BlogPosting or Article JSON-LD built from the post — headline, dates, author, publisher, image, tags and categories."
url: https://roundly-consulting.com/open-source/docs/posts-for-laravel/structured-data
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Posts for Laravel](https://roundly-consulting.com/open-source/docs/posts-for-laravel.md)

# 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:

```php
'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'),
    ],
],
```

```php
$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 crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## 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.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/posts-for-laravel.md)
