1// For
2@for ($i = 0; $i < max_value; $i++)
3 //your code
4@endfor
5//Foreach
6@foreach ($items as $item)
7 //your code
8@endforeach
1<div>
2 @for ($i = 0; $i < $max; $i++) //Where $max is whatever you need as break condition.
3 <p>{{ $i }}</p> //This would print $i in a paragraph. You do whatever you need here.
4 @endfor
5</div>
1@for ($i = 0; $i < 10; $i++)
2 The current value is {{ $i }}
3@endfor
4
5@foreach ($users as $user)
6 <p>This is user {{ $user->id }}</p>
7@endforeach
8
9@forelse ($users as $user)
10 <li>{{ $user->name }}</li>
11@empty
12 <p>No users</p>
13@endforelse
14
15@while (true)
16 <p>I'm looping forever.</p>
17@endwhile
1@forelse ($users as $user)
2 <li>{{ $user->name }}</li>
3@empty
4 <p>No users</p>
5@endforelse
1@if (count($records) === 1)
2 I have one record!
3@elseif (count($records) > 1)
4 I have multiple records!
5@else
6 I don't have any records!
7@endif
1$loop->index Returns a 0-based current loop iteration; 0 would mean the first iteration
2$loop->iteration Returns a 1-based current loop iteration; 1 would mean the first iteration
3$loop->remaining Number of iterations remaining in the loop; if there are a total of 10 iterations and the current iteration is 3, it would return 7
4$loop->count Returns the total number of iterations or the total number of items in the array
5$loop->first Returns true if it is the first iteration or item in the loop else returns false.
6$loop->last Returns true if it is the last iteration or item in the loop else return false.
7$loop->depth Returns the depth or nesting level of the current loop; returns 2 if it is a loop within a loop and 3 if it is nested one level more
8$loop->parentIf this loop is nested within another @foreach loop, parent returns the parent’s loop