It is right:
@foreach ($collection as $index => $element) {{$index}} - {{$element['name']}} @endforeach
And you have to use index + 1 because the index starts at 0.
Using source PHP in a 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>
Adnan source share