我有以下循环,其中我从查询中提取值并用表编写表,在该字段中,我需要根据从发货日期到今天为止所经过的天数,更改年龄的字段我已经在CSS中尝试过了[data-age> 180],但是我只遇到错误,而且找不到与我的需求类似的情况,另外,id喜欢在循环内进行操作,而不是另外的代码,因为它弄乱了我的视线@foreach($shipments as $shipment) <tr> <td data-title="id">{{$shipment->id}}</td> <td class=tracking data-title="tracking">{{$shipment->tracking}}</td> <td data-title="PartNumber">{{$shipment->PartNumber}}</td> <td data-title="DateShipped">{{$shipment->DateShipped}}</td> <td data-title="age" data-age="{{ (int) floor( (time() - strtotime($shipment->DateShipped)) / (60 * 60 * 24) ) }}" >{{ (int) floor( (time() - strtotime($shipment->DateShipped)) / (60 * 60 * 24) ) }} days </td> <td data-title="Qtyorder">{{$shipment->Qtyorder}}</td> <td data-title="QtyShipped">{{$shipment->QtyShipped}}</td> <td data-title="QtyBckorder">{{$shipment->QtyBckorder}}</td> <td data-title="purchaseOrder">{{$shipment->purchaseOrder}}</td> <td data-title="OrderNumber">{{$shipment->OrderNumber}}</td> <td data-title="paperwork">{{$shipment->paperwork}}</td> <td data-title="VMIreceived">{{$shipment->VMIreceived}}</td> <td data-title="VMIticketNumber">{{$shipment->VMIticketNumber}}</td> <td data-title="VMILRB">{{$shipment->VMILRB}}</td> <td> <a href="{{ route('shipment.edit',$shipment->id)}}" class="btn btn-primary" > Edit </a> </td> <td> <form action="{{ route('shipment.destroy', $shipment->id)}}" method="post"> @csrf @method('DELETE') <button class="btn btn-danger" type="submit">Delete</button> </form> </td> </tr>@endforeach
2 回答
狐的传说
TA贡献1804条经验 获得超3个赞
未经测试,但是您可以尝试以下操作:
@foreach($shipments as $shipment)
@php
$time_passed = $shipment->DateShipped->diffInSeconds(now());
@endphp
<tr>
<td class="{{ time_passed > some_number ? 'class_value_if_true' : 'class_value_if_false' }}">
{{ $time_passed }}
</td>
</tr>
@endforeach
- 2 回答
- 0 关注
- 107 浏览
添加回答
举报
0/150
提交
取消