I’m tring to check if null
with @if
for data in show.blade
<li id="step6"><strong>Schritt 6<br>@foreach($dbQuery as $query){{$query->sixth_step}}@endforeach</strong></li>
if sixth_step
is null to remove the <li> list item element
tried the following but not working
@foreach($dbQuery as $query){{$query->sixth_step}}
if({{$query->sixth_step}} !=null)
<li id="step6"><strong>Schritt 6<br>@foreach($dbQuery as $query){{$query->sixth_step}}@endforeach</strong></li>
endif
@endforeach
dd($query->sixth_step);
gives null
Also tried @if(isset
@if(empty
didn’t work
What is the best way to hide the <li>
element when sixth_step is null?
2
Answers
If the code you provided is the real code,
{{ }}
inside theif
statement. You can rewrite it like@if($query->sixth_step)
@
before theif
<li>
Or provide the exact error what you are getting.
Please check the refactored code below
You can use
is_null()
to specifically target only fornull
values because other methods consider false, [], 0, null all as same.