Sheath rule
blade-no-else-condition
@else takes no condition: @else(...) is silently discarded and @else if(...) renders literal text. Use @elseif.
as a dangerous fix. See Auto-fix.
#Why
Both misspellings of @elseif compile without a whisper of complaint, and
each breaks differently:
@else($b) -> <?php else: ?> arguments silently discarded;
the branch ALWAYS renders
@else if($b) -> <?php else: ?> if($b) compiles the @else, then leaves
"if($b)" behind as page text
The first is the quiet one: the template reads as a conditional branch, the
page renders it unconditionally, and nothing ever errors. The second at least
leaves if($b) visible on the rendered page. Both mean @elseif($b).
#Examples
#Bad
@if($user->isAdmin())
<p>Admin</p>
@else($user->isEditor())
<p>Editor</p>
@endif
@if($status === 'active')
<span>Active</span>
@else if($status === 'pending')
<span>Pending</span>
@endif
#Good
@if($user->isAdmin())
<p>Admin</p>
@elseif($user->isEditor())
<p>Editor</p>
@else
<p>Member</p>
@endif
{{-- Prose on the line after @else is just content --}}
@if($subscribed)
<p>Thanks for subscribing.</p>
@else
if you change your mind, subscribe any time.
@endif
#Auto-fix
@else($b) rewrites to @elseif($b). The fix is dangerous because the
branch becomes conditional instead of always rendering. It runs only with
--fix --dangerous.
{{-- before --}}
@else($user->isEditor())
{{-- after --}}
@elseif($user->isEditor())
The @else if(...) spelling gets no fix because the end of the intended
condition cannot be determined. The diagnostic says what to write instead.
#Notes
@else ifis reported only whenif(follows@elseon the same line; prose on the next line, or same-line text that is notif(...), never flags.- An
@elsecarrying arguments is reported wherever it appears, including an orphaned one outside any@ifblock.
#Related Rules
- blade-unclosed-directives - unpaired block directives
- blade-valid-directive-arguments - argument defects Blade compiles without warning