A
A
an5432019-02-12 10:05:23
Laravel
an543, 2019-02-12 10:05:23

Laravel check for even odd and last?

Hello ! Tell me, there is a cycle in the blade
how to make the counter shorter, check the counter for even / odd and if the counter value is the last.

@foreach($acts as $key => $value)
                          

@endforeach

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
Vlad, 2019-02-12
@an543

In recent versions of Laravel, there is a $loop variable in the loop:

@if ($loop->last)
    This is the last iteration.
@endif

And the parity check is done like this:
@if ($loop->index % 2 == 0)
    Четное
@else
    Нет
@endif

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question