All rules

Sheath rule

blade-forelse-has-empty

Reports a @forelse block with no @empty branch.
Package
Core
Category
Blade
Default severity
error by default
Auto-fix
Manual fix

#Why

@empty is not optional. @forelse compiles the loop and the empty branch as one unit, so leaving @empty out produces PHP that does not parse, and the page fails with a syntax error in the compiled view.

If the empty case genuinely needs no output, @foreach is the directive for that.

#Examples

#Bad

<!-- @forelse without @empty compiles to invalid PHP -->
@forelse($users as $user)
<p>{{ $user->name }}</p>
@endforelse
<!-- Missing @empty block -->
@forelse($items as $item)
<li>{{ $item->title }}</li>
@endforelse

#Good

<!-- @forelse with @empty provides good UX -->
@forelse($users as $user)
<p>{{ $user->name }}</p>
@empty
<p>No users found.</p>
@endforelse
<!-- Or use @foreach if you don't need empty handling -->
@foreach($users as $user)
<p>{{ $user->name }}</p>
@endforeach

#Notes

  • If you don't need empty state handling, use @foreach instead
  • The @empty block can contain any content: messages, empty states, CTAs, etc.
  • A missing branch may indicate that @foreach was intended

#Related Rules