我想在php条件中调用{{$barang->;stock}},并返回文本值
我想在php条件中调用{{$barang->;stock}},并返回文本值,php,html,laravel,routes,Php,Html,Laravel,Routes,{{$barang->stock}这是查看我的数据库值的代码。我想用它来做个条件- “如果({{$barang->stock}}>=1;“就绪库存”,“库存为空”)” 身份证件 夹克颜色 股票 产品销售 价格 产品状态 创建于 背景 @foreach($barang作为$barang) {{$barang->id} {{$barang->color} {{$barang->stock} {{$barang->sales} Rp{{$barang->price} {{如果($barang->st
{{$barang->stock}
这是查看我的数据库值的代码。我想用它来做个条件-
“如果({{$barang->stock}}>=1;“就绪库存”,“库存为空”)”
身份证件
夹克颜色
股票
产品销售
价格
产品状态
创建于
背景
@foreach($barang作为$barang)
{{$barang->id}
{{$barang->color}
{{$barang->stock}
{{$barang->sales}
Rp{{$barang->price}
{{如果($barang->stock>=1)}
{{$barang->created_at}
@csrf
@方法('DELETE')
@endforeach
{{$barang->stock>=1?'Ready stock':'stock Empty'}
那么如果我有这行代码,我想做一个条件,如果true class=pd设置如果false=ds设置{{($barang->stock>=1?'Ready stock':'stock Empty')}
{code>{{$barang->stock>=1?'Ready stock':'stock Empty'}是的,我的意思是如果true class=pd设置+“Ready stock”text如果为false class=ds setting+“Stock Empty”text请尝试是否有效并让我知道-{{{$barang->Stock>=1?'Ready Stock':'Stock Empty'}}
如果您还想将其用作类名。请不要声明为单独的单词。试着这样做-{{$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>
@endforeach
<tbody>
</table>
<td><button class="pd-setting {{ $barang->stock >= 1 ? 'ready-stock' : 'stock-empty' }}">{{ $barang->stock >= 1 ? 'Ready Stock' : 'Stock Empty' }}</button></td>