我有以下循環(huán),其中我從查詢(xún)中提取值并用表編寫(xiě)表,在該字段中,我需要根據(jù)從發(fā)貨日期到今天為止所經(jīng)過(guò)的天數(shù),更改年齡的字段我已經(jīng)在CSS中嘗試過(guò)了[data-age> 180],但是我只遇到錯(cuò)誤,而且找不到與我的需求類(lèi)似的情況,另外,id喜歡在循環(huán)內(nèi)進(jìn)行操作,而不是另外的代碼,因?yàn)樗獊y了我的視線(xiàn)@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 回答

狐的傳說(shuō)
TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超3個(gè)贊
未經(jīng)測(cè)試,但是您可以嘗試以下操作:
@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

吃雞游戲
TA貢獻(xiàn)1829條經(jīng)驗(yàn) 獲得超7個(gè)贊
嘗試一行if語(yǔ)句
{{ $condition ? value if true : value if false }}
- 2 回答
- 0 關(guān)注
- 135 瀏覽
添加回答
舉報(bào)
0/150
提交
取消