I have a component that outputs the $slot. But I want to do something like:
Component
<x-alert></x-alert>
<div>
@if ($slot)
{{ $slot }}
@else
No available content
@endif
</div>
I have a component that outputs the $slot. But I want to do something like:
Component
<x-alert></x-alert>
<div>
@if ($slot)
{{ $slot }}
@else
No available content
@endif
</div>
$slot
is an instance of the Illuminate\Support\HtmlString
class. So you can use the isNotEmpty
method:
<div>
@if ($slot->isNotEmpty())
{{ $slot }}
@else
No available content
@endif
</div>
the variable $slot
in laravel components is prepared as Object of type Illuminate\Support\HtmlString
so it need to be checked like this :
<div>
@if(strlen($slot->toHtml()) != 0)
{{$slot}}
@else
slot is empty
@endif
Try this :
<div>
@if (isset($slot) && $slot != null )
{{ $slot }}
@else
No available content
@endif
</div>
© 2022 - 2024 — McMap. All rights reserved.