Dynamic number of rows in Laravel Blade
This is correct:
@foreach ($collection as $index => $element)
{{$index}} - {{$element['name']}}
@endforeach
And you must use index+1 because index starts from 0.
Using raw PHP in view is not the best solution. Example:
<tbody>
<?php $i=1; @foreach ($aaa as $value)?>
<tr>
<td><?php echo $i;?></td>
<td><?php {{$value->name}};?></td>
</tr>
<?php $i++;?>
<?php @endforeach ?>
in your case:
<thead>
<th>number</th>
<th>name</th>
</thead>
<tbody>
@foreach ($aaa as $index => $value)
<tr>
<td>{{$index}}</td> // index +1 to begin from 1
<td>{{$value}}</td>
</tr>
@endforeach
</tbody>
Try $loop->iteration
variable.
`
<thead>
<th>number</th>
<th>name</th>
</thead>
<tbody>
@foreach ($aaa as $value)
<tr>
<td>{{$loop->iteration}}</td>
<td>{{$value}}</td>
</tr>
@endforeach
</tbody>
`