laravel loop variable

Solutions on MaxInterview for laravel loop variable by the best coders in the world

showing results for - "laravel loop variable"
Amanda
28 Jul 2017
1@foreach ($users as $user)
2    @if ($loop->first)
3        This is the first iteration.
4    @endif
5
6    @if ($loop->last)
7        This is the last iteration.
8    @endif
9
10    <p>This is user {{ $user->id }}</p>
11@endforeach
Link
21 Mar 2016
1<ul>
2@foreach ($pages as $page)
3    <li>{{ $loop->iteration }}: {{ $page->title }}
4        @if ($page->hasChildren())
5        <ul>
6        @foreach ($page->children() as $child)
7            <li>{{ $loop->parent->iteration }}.{{ $loop->iteration }}:
8                {{ $child->title }}</li>
9        @endforeach
10        </ul>
11        @endif
12    </li>
13@endforeach
14</ul>
Lukas
16 Feb 2019
1Property			Description
2$loop->index		The index of the current loop iteration (starts at 0).
3$loop->iteration	The current loop iteration (starts at 1).
4$loop->remaining	The iterations remaining in the loop.
5$loop->count		The total number of items in the array being iterated.
6$loop->first		Whether this is the first iteration through the loop.
7$loop->last			Whether this is the last iteration through the loop.
8$loop->even			Whether this is an even iteration through the loop.
9$loop->odd			Whether this is an odd iteration through the loop.
10$loop->depth		The nesting level of the current loop.
11$loop->parent		When in a nested loop, the parent's loop variable.