How to work with slots in Laravel Blade files

Categorized as Laravel Tagged ,

To check if a $slot has some content, this doesn’t work because $slot is an object and will always be true.

<div>
  {{ $slot ?: 'Default' }}
</div>

Use different methods on the $slot object instead. See Illuminate\View\ComponentSlot.

<div>
    {{ $slot->isNotEmpty() ? $slot : 'Default' }}
</div>

Leave a reply

Your email address will not be published. Required fields are marked *