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

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...