Laravel : numbers count variable in foreach loop in laravel

In this tutorial learn how to numbers count variable in foreach loop in laravel. In Laravel count the each iteration of the foreach loop using index of foreach start 1 using the laravel syntax.

Numbers count variable example using foreach in view file.

   @foreach($categories  as $index =>  $category)
       <tr>
          <td>{{$index+1}}</td>
          <td>{{$category->name}}</td>
       </tr>
   @endforeach

Here, the index value start from  0 by default, so we added +1 to start from 1  iteration.

No comments:

Post a Comment