Buscar..


Introducción

Nuevas características, mejoras y cambios de Laravel 5.2 a 5.3.

La variable $ loop

Se sabe por un tiempo que tratar con bucles en Blade ha sido limitado, a partir de 5.3 hay una variable llamada $loop disponible

@foreach($variables as $variable)

    // Within here the `$loop` variable becomes available

    // Current index, 0 based
    $loop->index;

    // Current iteration, 1 based
    $loop->iteration;

    // How many iterations are left for the loop to be complete
    $loop->remaining;

    // Get the amount of items in the loop
    $loop->count;

    // Check to see if it's the first iteration ...
    $loop->first;

    // ... Or last iteration
    $loop->last;

    //Depth of the loop, ie if a loop within a loop the depth would be 2, 1 based counting.
    $loop->depth;

    // Get's the parent `$loop` if the loop is nested, else null
    $loop->parent;

@endforeach


Modified text is an extract of the original Stack Overflow Documentation
Licenciado bajo CC BY-SA 3.0
No afiliado a Stack Overflow