Blade if(isset) is not working Laravel
{{ $usersType or '' }}
is working fine. The problem here is your foreach loop:
@foreach( $usersType as $type )
<input type="checkbox" class='default-checkbox'> <span>{{ $type->type }}</span>
@endforeach
I suggest you put this in an @if()
:
@if(isset($usersType))
@foreach( $usersType as $type )
<input type="checkbox" class='default-checkbox'> <span>{{ $type->type }}</span>
@endforeach
@endif
You can also use @forelse. Simple and easy.
@forelse ($users as $user)
<li>{{ $user->name }}</li>
@empty
<p>No users</p>
@endforelse
@isset($usersType)
// $usersType is defined and is not null...
@endisset
For a detailed explanation refer documentation:
In addition to the conditional directives already discussed, the
@isset
and@empty
directives may be used as convenient shortcuts for their respective PHP functions
Use ?? , 'or' not supported in updated version.
{{ $usersType or '' }} ❎
{{ $usersType ?? '' }} ✅