The issue is that Blade interprets the @ character as the start of a Blade directive (like @if, @foreach, etc). When you use JSON-LD, the @context and @type keys are standard, but Blade tries to parse them, causing the syntax error.
Solution:
You need to tell Blade to ignore the contents of your <script type="application/ld+json"> block. The best way to do this is to use the @verbatim directive, which tells Blade not to parse anything inside.
How to fix your code:
Replace your JSON-LD block with the following:
<script type="application/ld+json">
@verbatim
{
"@context": "https://schema.org",
"@type": "NewsArticle",
"headline": "Title of a News Article",
"image": [
"https://example.com/photos/1x1/photo.jpg",
"https://example.com/photos/4x3/photo.jpg",
"https://example.com/photos/16x9/photo.jpg"
],
"datePublished": "2024-01-05T08:00:00+08:00",
"dateModified": "2024-02-05T09:20:00+08:00",
"author": [{
"@type": "Person",
"name": "Jane Doe",
"url": "https://example.com/profile/janedoe123"
}, {
"@type": "Person",
"name": "John Doe",
"url": "https://example.com/profile/johndoe123"
}]
}
@endverbatim
</script>
Note:
- Place
@verbatimimmediately after the opening<script>tag and@endverbatimbefore the closing</script>. - If you need to insert dynamic PHP variables into your JSON-LD, you’ll need a different approach (let me know if you need that).
Summary:
Use @verbatim to prevent Blade from parsing @context and @type in your JSON-LD. This will resolve the syntax error.