php - 我想在 php 条件下调用 {{$barang->stock}} 并返回文本值
问题描述
{{$barang->stock}}
这是查看我的数据库值的代码。我想把它用于一个条件 -
"如果 ({{$barang->stock}} >= 1; "现货"; "库存空") "
<table>
<thead>
<tr>
<th>ID</th>
<th>Jacket Color</th>
<th>Stock</th>
<th>Product Sales</th>
<th>Price</th>
<th>Product Status</th>
<th>Create At</th>
<th>Setting</th>
</tr>
</thead>
<tbody>
@foreach($barang as $barang)
<tr>
<td>{{$barang->id}}</td>
<td>{{$barang->color}}</td>
<td>{{$barang->stock}}</td>
<td>{{$barang->sales}}</td>
<td>Rp {{$barang->price}}</td>
<td>{{if ($barang->stock >= 1)}}</td>
<td>{{$barang->created_at}}</td>
<td>
<button href="{{ route('barang.edit',$barang->id)}}" data-toggle="tooltip" title="Edit" class="pd-setting-ed"><i class="fa fa-pencil-square-o" aria-hidden="true"></i></button>
<form action="{{ route('barang.destroy', $barang->id)}}" method="post">
@csrf
@method('DELETE')
<button data-toggle="tooltip" title="Trash" class="pd-setting-ed"><i class="fa fa-trash-o" aria-hidden="true"></i></button>
</form>
</td>
</tr>
@endforeach
<tbody>
</table>
解决方案
<td><button class="pd-setting {{ $barang->stock >= 1 ? 'ready-stock' : 'stock-empty' }}">{{ $barang->stock >= 1 ? 'Ready Stock' : 'Stock Empty' }}</button></td>
推荐阅读
- spring-integration - 具有大负载大小的 http 出站网关是否有任何限制
- node.js - 如何构建多人游戏的后端
- grasshopper - 在哪里向蚱蜢定义添加表面以创建显示的结果?
- python - 不断收到 ModuleNotFoundError: No module named 'pynini' in Pycharm 和 Spyder
- java - 表中键数的准确范围
- javascript - js中的两个for循环。无法在嵌套的 for 循环上工作
- javascript - Angular 2:滚动动画
- guidewire - 如何在 Guidewire 中安装 DCEVM?
- r - 移动 geom_label 的框,使它们不重叠
- elasticsearch - 在 Elasticsearch 中更改设置的最佳解决方案