我只想显示我所拥有的特长,即它们在数据库的同一表中的值等于1,而当它等于0时不显示。我试图制作if语句,但它们返回错误。知道如何从数据库中获取值并进行检查吗?
@foreach($specialties as $key => $specialty)
{{--@if ($value->{$key::is_template} = 1)--}}
@if(value("{{$key->is_template}}") === 1)
<li class="pcoded-hasmenu pcoded-trigger" dropdown-icon="style3" subitem-icon="style7">
<a href="#">
<span class="pcoded-micon"><i class="ti-calendar"></i><b>M</b></span>
<span class="pcoded-mtext">{{$key}}</span>
<span class="pcoded-mcaret"></span>
</a>
<ul class="pcoded-submenu">
@foreach($specialty as $training)
<li class=" ">
<a href="{{route('practitionerView', $training->training_id)}}">
<span class="pcoded-micon"><i class="ti-angle-right"></i></span>
<span class="pcoded-mtext">{{$training->name}}</span>
<span class="pcoded-mcaret"></span>
</a>
</li>
@endforeach
</ul>
</li>
@endif
@endforeach
答案 0 :(得分:0)
假设$specialties
是这样的数组/集合:
$specialties = [
'a' => new Specialty(['is_template' => 1]),
'b' => new Specialty(['is_template' => 0]),
'c' => new Specialty(['is_template' => 1]),
];
条件@if ($specialty->is_template === 1)
或@if ($specialty->is_template)
可行。
或者,如果您想保存几行,则可以用@foreach($specialties->where('is_template', 1) as $key => $specialty)
替换foreach(这适用于Collection而不是常规数组)