Here is my code,
<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>
When i execute this code, the serial number remains 1 for addition of more values.. For each and every value that has been added was with serial number 1.. How to get the increment of values like 2,3,4.. so on??
while you are using foreach why use extra variable you can do that with foreach like that
@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
but if want to use your method then just simply put <?php $j++; ?>
inside the foreach loop
it's because your increment is after loop. place it in side foreach
loop
<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>
<?php $j++; ?>
@endforeach
</tbody>
Your increment counter must be within foreach loop.
Write your lines as below:-
<?php $j++; ?>
@endforeach
OR you can do that without using counter
<?php $items = array_values($items);
array_unshift($items,"");
unset($items[0]);
?>
@foreach($items as $k => $item)
now use $k
Do it simple as
@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
</tbody>
Your Code should be look like:
<tbody>
<?php $j = 1; ?>
@foreach($items as $item)
<?php $j++; ?>
<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
</tbody>
Simply try below code :
@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