<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: GaijinAnime</title>
    <description>The latest articles on DEV Community by GaijinAnime (@gaijinanime_a0c580c5a205f).</description>
    <link>https://dev.to/gaijinanime_a0c580c5a205f</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3897481%2F3b46af21-e0bd-435e-bbab-d3cc532fd6b4.png</url>
      <title>DEV Community: GaijinAnime</title>
      <link>https://dev.to/gaijinanime_a0c580c5a205f</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/gaijinanime_a0c580c5a205f"/>
    <language>en</language>
    <item>
      <title>How Blade's @context directive broke our JSON-LD</title>
      <dc:creator>GaijinAnime</dc:creator>
      <pubDate>Sat, 25 Apr 2026 15:18:28 +0000</pubDate>
      <link>https://dev.to/gaijinanime_a0c580c5a205f/how-blades-context-directive-broke-our-json-ld-2976</link>
      <guid>https://dev.to/gaijinanime_a0c580c5a205f/how-blades-context-directive-broke-our-json-ld-2976</guid>
      <description>&lt;h1&gt;
  
  
  How Blade's &lt;code&gt;@context&lt;/code&gt; directive broke our JSON-LD
&lt;/h1&gt;

&lt;p&gt;If you have schema.org JSON-LD inside a Blade template and you upgrade to Laravel 12, you may have just broken those views. Quietly. Without a deprecation warning.&lt;/p&gt;

&lt;p&gt;We hit this last week on a blog index running 12.44.0. The page returned &lt;code&gt;HTTP 500&lt;/code&gt; for every visitor for three weeks before anyone noticed. There is a public issue with the same symptom against 12.20+: &lt;a href="https://github.com/laravel/framework/issues/56248" rel="noopener noreferrer"&gt;laravel/framework#56248&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This is the 90-second writeup so you do not waste an afternoon on it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Symptom
&lt;/h2&gt;

&lt;p&gt;Any Blade view that contains &lt;code&gt;"@context"&lt;/code&gt; as a literal key in inline JSON-LD throws:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;syntax error, unexpected end of file, expecting "elseif" or "else" or "endif"
(View: /resources/views/blog/index.blade.php)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The view itself parses fine. Every &lt;code&gt;@if/@endif&lt;/code&gt;, &lt;code&gt;@foreach/@endforeach&lt;/code&gt;, &lt;code&gt;@push/@endpush&lt;/code&gt; is balanced. Yet the compiled view in &lt;code&gt;storage/framework/views/&lt;/code&gt; is malformed.&lt;/p&gt;

&lt;h2&gt;
  
  
  Cause
&lt;/h2&gt;

&lt;p&gt;Laravel 12 added the &lt;code&gt;@context&lt;/code&gt; Blade directive as part of the request-scoped Context feature. The trait lives at &lt;code&gt;vendor/laravel/framework/src/Illuminate/View/Compilers/Concerns/CompilesContexts.php&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;@context&lt;/code&gt; is an opening block directive. It expects a matching &lt;code&gt;@endcontext&lt;/code&gt; later in the template.&lt;/p&gt;

&lt;p&gt;But schema.org JSON-LD looks like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"application/ld+json"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@context&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;https://schema.org&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@type&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Blog&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;name&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;...&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When the Blade compiler scans the template, it sees the literal text &lt;code&gt;@context&lt;/code&gt; inside the JSON, treats it as the opening of a directive block, and waits for &lt;code&gt;@endcontext&lt;/code&gt;. None ever appears. The compiler eventually reports the error at the end of the file, with a stack trace that points 200 lines past the actual cause.&lt;/p&gt;

&lt;p&gt;If you peek at the compiled file in &lt;code&gt;storage/framework/views/&lt;/code&gt;, you can see the bad output:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;"&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt; &lt;span class="nv"&gt;$__contextArgs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[];&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nf"&gt;context&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;has&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$__contextArgs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]))&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt;
&lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;isset&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nv"&gt;$__contextPrevious&lt;/span&gt;&lt;span class="p"&gt;[]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nv"&gt;$value&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;context&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;-&amp;gt;&lt;/span&gt;&lt;span class="nf"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$__contextArgs&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;]);&lt;/span&gt; &lt;span class="cp"&gt;?&amp;gt;&lt;/span&gt;": "https://schema.org",
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That was supposed to be a literal JSON key.&lt;/p&gt;

&lt;h2&gt;
  
  
  Scope
&lt;/h2&gt;

&lt;p&gt;This affects only &lt;strong&gt;literal &lt;code&gt;@context&lt;/code&gt;&lt;/strong&gt; text inside a &lt;code&gt;.blade.php&lt;/code&gt; file. JSON-LD emitted via &lt;code&gt;json_encode($data)&lt;/code&gt;, &lt;code&gt;Js::from($data)&lt;/code&gt;, or &lt;code&gt;@json($data)&lt;/code&gt; is unaffected — those write their output through PHP, never through Blade's directive parser.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fix
&lt;/h2&gt;

&lt;p&gt;Two characters. Escape the &lt;code&gt;@&lt;/code&gt; with another &lt;code&gt;@&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight diff"&gt;&lt;code&gt; &amp;lt;script type="application/ld+json"&amp;gt;
 {
&lt;span class="gd"&gt;-    "@context": "https://schema.org",
&lt;/span&gt;&lt;span class="gi"&gt;+    "@@context": "https://schema.org",
&lt;/span&gt;     "@type": "Blog",
     ...
 }
 &amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Blade renders &lt;code&gt;@@context&lt;/code&gt; as a literal &lt;code&gt;@context&lt;/code&gt; in the rendered HTML. No other JSON-LD keys collide — &lt;code&gt;@type&lt;/code&gt;, &lt;code&gt;@id&lt;/code&gt;, &lt;code&gt;@graph&lt;/code&gt; are not Blade directives — so this is the only character you need to escape.&lt;/p&gt;

&lt;p&gt;If your views were cached during the broken state, run &lt;code&gt;php artisan view:clear&lt;/code&gt; once. Laravel recompiles modified Blade files automatically on the next request, so you only need this if a stale compiled view is sticking around.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to find every instance
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;grep&lt;/span&gt; &lt;span class="nt"&gt;-rn&lt;/span&gt; &lt;span class="s1"&gt;'"@context"'&lt;/span&gt; resources/views
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Anywhere that pattern appears, escape it. Worth doing as a one-line audit even if your blog index works — you may have JSON-LD in other templates (FAQ schema, Product schema, Breadcrumb schema, Article schema). All of them use &lt;code&gt;@context&lt;/code&gt; as a top-level key. All of them break the same way after the upgrade.&lt;/p&gt;

&lt;p&gt;We found three locations. One was throwing 500s on every hit. The other two were inside templates that happened not to be visited since the upgrade.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I would change about Laravel's behavior
&lt;/h2&gt;

&lt;p&gt;A parse-time warning when the Blade compiler sees &lt;code&gt;@context&lt;/code&gt; followed by &lt;code&gt;:&lt;/code&gt; rather than &lt;code&gt;(&lt;/code&gt; or whitespace would catch this in development. JSON-LD keys are the dominant case for that pattern; user-defined directives almost always take parens or arguments. A heuristic warning seems cheap and high-value.&lt;/p&gt;

&lt;p&gt;For now: &lt;code&gt;@@context&lt;/code&gt; and move on.&lt;/p&gt;




&lt;p&gt;(Disclosure: I work on Apps66, where this bug bit us. The fix is the only point.)&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>php</category>
      <category>webdev</category>
      <category>debugging</category>
    </item>
  </channel>
</rss>
