I\'m trying to create blade directive which echo variable (if variable defined) or echo \"no data\" if variable undefined.
This is my code in AppServiceProvider.ph
For Laravel 5.7 onwards use.
{{ $checkvariable ?? 'not-exist' }}
For Laravel version >=5.7
{{ $value ?? '' }}
For Laravel version <5.7
{{ $value or '' }}
The @empty
directive might be useful:
@empty($var)
$var is unset or false-y
@endempty
For the last version of Larvael make the variable optional in the blade template.
Replace $myvar
with
{{ $myvar }} with {{ $myvar?? '' }}
Blade has a directive to check if a variable is set:
@isset($var)
@endisset
If you trying check a bool variable you can use @unless
<input type="text" class="@unless ($variable) d-none @endunless" >