繁体   English   中英

如何在laravel中添加休假计数器?

[英]How can I add leave counter in laravel?

我有2列医疗和休闲假,我的数据库中有2个医疗叶,所以我想要计数离开,而不是它显示我1 1,我该如何解决?

这是我的视图文件代码

<td>
@foreach($employeeLeave as $empleave)
@if($empName['personal_detail']['first_name'] == $empleave->name)
   @if($empleave->type == 'casual')
      {{ count([$empleave->type]) }}
   @endif
@endif
@endforeach
</td>
<td>
@foreach($employeeLeave as $empleave)
@if($empName['personal_detail']['first_name'] == $empleave->name)
   @if($empleave->type == 'medical')
      {{ count([$empleave->type]) }}
   @endif
@endif
@endforeach
</td>

您可以先执行循环计数,然后填充

@php
$casualCount = $medicalCount = 0;
@endphp
@foreach($employeeLeave as $empleave)
   @if($empName['personal_detail']['first_name'] == $empleave->name)
        @if($empleave->type == 'casual')
             @php $casualCount++; @endphp
        @endif
        @if($empleave->type == 'medical')
            @php $medicalCount++; @endphp
        @endif
   @endif
@endforeach

然后你的HTML

<td>
{{ $casualCount }}
</td>

<td>
{{ $medicalCount }}
</td>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM