为了账号安全,请及时绑定邮箱和手机立即绑定

我想在 php 条件下调用 {{$barang->stock}} 并返回文本值

我想在 php 条件下调用 {{$barang->stock}} 并返回文本值

PHP
月关宝盒 2021-07-06 18:45:47
{{$barang->stock}}这是查看我的数据库值的代码。我想用它来满足条件 -"if ({{$barang->stock}} >= 1; "Ready Stock"; "Stock Empty") "                    <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>
查看完整描述

1 回答

?
海绵宝宝撒

TA贡献1809条经验 获得超8个赞

<td><button class="pd-setting {{ $barang->stock >= 1 ? 'ready-stock' : 'stock-empty' }}">{{ $barang->stock >= 1 ? 'Ready Stock' : 'Stock Empty' }}</button></td>


查看完整回答
反对 回复 2021-07-09
  • 1 回答
  • 0 关注
  • 150 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信