Sheath rule
blade-no-compiler-directives-in-comments
Blade comments must not mention
@php, @endphp, @verbatim, or @endverbatim.
#Why
Blade processes @php ... @endphp and @verbatim ... @endverbatim before
removing {{-- --}} comments. A marker inside a comment can therefore pair with
a live directive elsewhere in the file:
{{-- TODO: maybe use @php here --}}
<div>middle content</div>
@php $x = 1; @endphp
This can produce invalid compiled PHP. The same issue applies to @endphp,
@verbatim, and @endverbatim. Reword or escape these directive names inside
Blade comments.
#Examples
#Bad
{{-- TODO: maybe use @php here --}}
<div>middle content</div>
@php $x = 1; @endphp
{{-- docs mention @verbatim --}}
{{-- close it with @endphp --}}
#Good
{{-- Escape the name when the comment really needs it --}}
{{-- use @@php for inline PHP --}}
{{-- TODO: extract this partial --}}
{{-- other directives are fine to mention: @if, @foreach --}}
{{-- Real raw blocks outside comments are what they are for --}}
@php
$total = $items->sum('price');
@endphp
#Notes
- The
@@phpescape prevents Blade from treating the mention as a directive. Rewording the comment also works. - HTML comments (
<!-- -->) do not shield content from Blade. Directive pairs inside them compile as they would elsewhere in the template. - No auto-fix is available because the intended wording cannot be inferred.
#Related Rules
- blade-unclosed-directives - unpaired block directives
- blade-valid-directive-arguments - prose and CSS that collide with directive names