Laravel Blade: Increment variable by 1 each time?
In Laravel 5.3 you can use The Loop Variable, $loop->iteration for concrete situation. https://laravel.com/docs/5.3/blade#the-loop-variable
Exapmle:
@foreach ($questions as $question)
<tr>
<th scope="row">{{ $loop->iteration }}</th>
<td>{{ $question->question }}</td>
<td>{{ $question->category_id }}</td>
</tr>
@endforeach
Add iterator to @foreach
:
@foreach($categories as $key => $category)
<li @if ($key === 0) class="active" @endif>
<a href="#tab_c{{$key+1}}" role="tab" data-toggle="tab">
{{$category->name}}
</a>
</li>
@endforeach
{{$key+1}}
in my example because in PHP iterator starts at 0.