There are special directives in the Balde template for each PHP conditional logics like if.. else, issetetc.
You can read more in Laravel’s official documentation here.
Conditional rendering directives are:
- @if.. @elseif..@else.. @endif
- @unless()…@endunless – Condition has to be false
- @isset()…@endisset
- @php ….@endphp – To write some PHP code into view file
Loop directives are:
- @for…@endfor
- @while…@endwhile
- @foreach…@endforeach
- @switch…@case…@default…@endswitch
- @forelse…@empty…@endforelse
- @while…@endwhile
- @continue
- @break
Also $loop variable has variety of useful properties like:
$loop->index | The index of the current loop iteration (starts at 0). |
$loop->iteration | The current loop iteration (starts at 1). |
$loop->remaining | The iterations remaining in the loop. |
$loop->count | The total number of items in the array being iterated. |
$loop->first | Whether this is the first iteration through the loop. |
$loop->last | Whether this is the last iteration through the loop. |
$loop->even | Whether this is an even iteration through the loop. |
$loop->odd | Whether this is an odd iteration through the loop. |
$loop->depth | The nesting level of the current loop. |
$loop->parent | When in a nested loop, the parent’s loop variable. |