我正在Laravel-5.8中开发一个项目。
控制器
public function index()
{
$identities = AppraisalIdentity::where('company_id', $userCompany)->get();
return view('appraisal.appraisal_identities.index')->with('identities', $identities);
}
index.blade.php
<tbody>
@foreach($identities as $key => $identity)
<td>
{{$key+1}}
</td>
<td>
{{$identity->appraisal_name ?? '' }}
</td>
<td>
{{ $identity->is_current ?? '' }}
</td>
@endforeach
我想要实现的是,当is_current为0时,它应该显示否为红色,当is_current为1时,它应该显示为绿色。< / p>
我该如何实现?
谢谢
答案 0 :(得分:1)
您可以为此使用Blade未转义的括号符号来添加具有以下样式或类的css span:
{!! $identity->is_current ? "<span class='green'>Yes</span>" : "<span class='red'>No</span>" !!}}
红色和绿色是您的颜色的样式类。
答案 1 :(得分:0)
您可以尝试使用Laravel blade's if statement:
<td>
@if ($identity->is_current)
<span style="color: green;">Yes</span>
@else
<span style="color: red;">No</span>
@endif
</td>