I am trying to do iterate with two different loops in my Blade file but the results keep repeating the numbers.
Results
0 1
1 2
2 3
3 4
These are the results I want.
1 2
3 4
5 6
7 8
Blade
@foreach($driver_recs as $page => $driver)
<div class="form-container">
@foreach($trip_count as $val => $trip)
@if($val == 2)
{{ $loop->parent->iteration }}
@endif
@endforeach
{{ $loop->iteration + 1 }}
</div>
@endforeach
You can split your numbers into chunks of 2 and then render them easily.
@foreach (collect(1,2,3,4,5,6,7,8)->chunk(2) as $chunk) {
<div class="form-container">
@foreach ($chunk as $number) {
{{ $number }}
@endforeach
</div>
@endforeach
Tying up your code logic to specific iteration numbers is a bad practice and a very big indication that you are probably doing things wrong.