php - 如何根据值在 HTML 单元格中添加类
问题描述
我有以下循环,我从查询中提取值并用它写一个表,在字段中我需要根据自发货日期和今天过去的天数更改 's 类
我已经在 CSS like[data-age >180] 中尝试过,但我只得到错误,而且我找不到与我的需求相似的案例,另外我喜欢在循环中而不是额外的代码段中执行它,因为它扰乱了我的视野
@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
解决方案
尝试单行 if 语句
{{ $condition ? value if true : value if false }}
推荐阅读
- nearprotocol - 收据是否对平台构成潜在安全风险?
- reactjs - 使用带有加载和 freeSolo 道具的 react material-ui 自动完成
- python - 圆形掩码 numpy 数组一步到位
- java - 可比 Generic 如何使用 ist
- python - 显示多个图像直方图
- reactjs - 有没有办法在 reactjs 应用程序中访问电话库?
- java - 如何从 gcp 存储桶中读取 XLS 文件
- ruby-on-rails - 搜索性能、Active Record、Postgres 和 Trigram 索引,如何拆分查询以强制 postgres 使用索引
- python - Stackdriver 日志记录未捕获 GKE 中的所有日志
- google-drive-api - Google Drive 评论 API 矩形标记