How access to $loop variable in nested foreach blead

Viewed 5897
@foreach($last_articles->chunk(3) as $row)
        @foreach($row as $last_article)
                @if($loop->index!=0) {{"in $loop"}} @endif
        @endforeach
        @if($loop->index!=0) {{"out $loop"}} @endif
@endforeach

how access to $loop of any of foreach, that was used in code?

2 Answers

In my case (Laravel 6.8) $loop->parent looks like this

[
{"iteration":1,"index":0,"remaining":1,"count":2,"first":true,"last":false,"odd":true,"even":false,"depth":1,"parent":null},
{"iteration":2,"index":1,"remaining":0,"count":2,"first":false,"last":true,"odd":false,"even":true,"depth":1,"parent":null}
]

to access the parent index $loop->parent->index

Related