这是我的代码,
<tbody>
<?php $j = 1; ?>
@foreach($items as $item)
<tr>
<td class="text-right">{{ $j }}</td>
<td>{{ $item->product_name }}</td>
<td>{{ $item->product_name2 }}</td>
<td>{{ $item-> quantity}}</td>
<td class="text-center"><a href="{{ route('Conversion.edit', $item->id) }}" class="btn btn-warning"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></td>
<td class="text-center">
{!! Form::open([
'method' => 'DELETE',
'route' => ['Conversion.destroy', $item->id]
]) !!}
{!! Form::button('<i class="glyphicon glyphicon-remove"></i>', array('type' => 'submit', 'class' => 'btn btn-danger')) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
<?php $j++; ?>
</tbody>
当我执行此代码时,序列号保持为 1 以添加更多值。对于已添加的每个值,序列号为 1 .. 如何获得 2、3、4 等值的增量...上??
当您使用 foreach 为什么要使用额外的变量时,您可以像这样使用 foreach
@foreach($items as $key =>$item)
<tr>
<td class="text-right"> {{$key+1}} </td>
<td>{{ $item->product_name }}</td>
<td>{{ $item->product_name2 }}</td>
<td>{{ $item-> quantity}}</td>
<td class="text-center"><a href="{{ route('Conversion.edit', $item->id) }}" class="btn btn-warning"><span class="glyphicon glyphicon-pencil" aria-hidden="true"></span></a></td>
<td class="text-center">
{!! Form::open([
'method' => 'DELETE',
'route' => ['Conversion.destroy', $item->id]
]) !!}
{!! Form::button('<i class="glyphicon glyphicon-remove"></i>', array('type' => 'submit', 'class' => 'btn btn-danger')) !!}
{!! Form::close() !!}
</td>
</tr>
@endforeach
但是如果想使用你的方法,那么只需简单地放在<?php $j++; ?>
foreach 循环中
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句