Laravel 12 introduced stricter parsing rules in Blade. That’s great for catching typos in directives—but it also broke something critical: structured data rendering.
If you’ve ever embedded JSON-LD into your Blade views for SEO, you might’ve seen your app crash with cryptic errors. The culprit? Blade’s interpretation of @context and @type as directives.
Let’s unpack what went wrong, why it matters, and how Laravel’s new @at-context directive fixes it.
😵 What Went Wrong: Blade vs. JSON-LD
Blade’s core feature is directive parsing. Any @ symbol followed by a word is treated as a directive—like @if, @foreach, or @csrf.
But structured data uses the same syntax:
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "Example",
"url": "https://example.com"
}
When this JSON is placed inside a Blade view:
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "Example"
}
</script>
Laravel 12.20+ throws a Call to undefined method Illuminate\View\Factory::context() error. Why? Because Blade thinks @context is a directive and tries to execute it.
This wasn’t a problem in earlier versions because Blade was more lenient. But Laravel 12’s stricter parsing broke valid JSON-LD—silently killing SEO for many apps.
🔍 Why This Matters
Structured data is the backbone of modern SEO. Google uses it to generate rich snippets, understand page context, and improve indexing.
If your Blade views can’t safely render JSON-LD, your site’s visibility suffers.
For Laravel devs building blogs, e-commerce platforms, or SaaS tools, this is a high-stakes issue.
✅ The Fix: Laravel 12.32’s @at-context Directive
Taylor Otwell and the Laravel team responded quickly. In Laravel 12.32, they introduced a new Blade directive: @at-context.
It tells Blade to treat everything inside the block as raw text—no directive parsing.
✅ Syntax:
@at-context
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "Example",
"url": "https://example.com"
}
</script>
@endat-context
Now, Blade renders the JSON exactly as written. No errors. No misinterpretation. Just clean, valid structured data.
🧪 Real-World Fix: Dynamic JSON-LD in Laravel
Let’s say you’re rendering blog post metadata:
@at-context
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "BlogPosting",
"headline": "{{ $post->title }}",
"author": {
"@type": "Person",
"name": "{{ $post->author->name }}"
},
"datePublished": "{{ $post->published_at->toIso8601String() }}"
}
</script>
@endat-context
This ensures:
- Dynamic values are injected safely
- JSON-LD remains valid
- Blade doesn’t choke on
@typeor@context
🧙♂️ The Laravel Solution: @verbatim + @at-context Magic
Laravel now gives us two powerful tools to tame Blade’s directive parser when working with raw content:
🔹 @verbatim: The Nuclear Option
Use @verbatim when you want Blade to ignore everything inside the block—including {{ }} interpolation.
@verbatim
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "{{ $siteName }}"
}
</script>
@endverbatim
⚠️ Problem: Blade won’t parse {{ $siteName }}—it’ll be rendered literally. That’s great for static JSON, but not ideal for dynamic content.
🔹 @at-context: The Precision Fix
Use @at-context when you want Blade to ignore @ symbols but still parse {{ }} expressions.
@at-context
<script type="application/ld+json">
{
"@context": "https://schema.org",
"@type": "WebSite",
"name": "{{ $siteName }}"
}
</script>
@endat-context
✅ Result: You get valid JSON-LD with dynamic values—and no Blade errors.
🧠 When to Use What
| Use Case | Recommended Directive |
|---|---|
Static JSON with @ and no {{ }} | @verbatim |
Dynamic JSON with @ and {{ }} | @at-context |
| Raw HTML or JS blocks | @verbatim |
| Structured data for SEO | @at-context |
Laravel’s solution is elegant:
@verbatim= full Blade bypass@at-context= selective Blade bypass
Together, they give you total control over how Blade parses your views—without compromising on SEO, performance, or DX.
💡 Developer Tips
- Use
@at-contextfor any block with@in JSON or script tags - Avoid using
@verbatimfor structured data—it disables all Blade parsing - Validate your JSON-LD with Google’s Rich Results Test
- Keep structured data dynamic—don’t hardcode values
🔮 Final Thoughts
Laravel 12’s stricter Blade parsing exposed a subtle but serious flaw in how we render structured data. The new @at-context directive is a thoughtful fix—one that preserves Blade’s power while respecting the realities of modern SEO.
If you’re building Laravel apps with embedded JSON-LD, this directive isn’t optional—it’s essential.
