Sheath rule
blade-forelse-empty-arguments
@empty branch of a @forelse must be bare; @empty(...) compiles to if(empty(...)) and the loop never closes.
as a dangerous fix. See Auto-fix.
#Why
@empty is two different directives. Bare, inside a @forelse, it is the
empty branch. With arguments, anywhere, it is the empty() conditional that
pairs with @endempty. Blade decides by the arguments alone, regardless of
position. Giving the forelse branch arguments therefore selects the
wrong directive:
@forelse($users as $user) -> foreach ($users as $user):
@empty($users) -> if(empty($users)): <- not the branch!
@endforelse -> endforeach; endif; <- foreach never closed
The foreach is never terminated, the compiled view is invalid PHP, and the
error points into storage/ instead of at this line. A space changes nothing:
@empty ($users) compiles the same way.
Standalone @empty($x) ... @endempty blocks outside a forelse are the
legitimate conditional and are never reported.
#Examples
#Bad
@forelse($users as $user)
<li>{{ $user->name }}</li>
@empty($users)
<li>No users found.</li>
@endforelse
@forelse($posts as $post)
<article>{{ $post->title }}</article>
@empty ($posts)
<p>Nothing published yet.</p>
@endforelse
#Good
@forelse($users as $user)
<li>{{ $user->name }}</li>
@empty
<li>No users found.</li>
@endforelse
{{-- The standalone conditional form, outside any forelse --}}
@empty($records)
<p>Nothing recorded.</p>
@endempty
#Auto-fix
The fix rewrites @empty($users) to a bare @empty. It is dangerous because
the arguments are discarded and the intended behavior cannot be inferred. It
runs only with --fix --dangerous.
{{-- before --}}
@empty($users)
{{-- after --}}
@empty
#Notes
@empty($value)does not satisfy the requirement for a bare@emptybranch. See blade-forelse-has-empty for the required@forelsestructure.- The diagnostic explains both meanings of
@emptyand identifies the bare form as the correction.
#Related Rules
- blade-forelse-has-empty - @forelse blocks should have an @empty clause
- blade-unclosed-directives - unpaired block directives