Laravel Introduction to laravel-5.3 The $loop variable


It is known for a while that dealing with loops in Blade has been limited, as of 5.3 there is a variable called $loop available

@foreach($variables as $variable)

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

    // Current index, 0 based

    // Current iteration, 1 based

    // How many iterations are left for the loop to be complete

    // Get the amount of items in the loop

    // Check to see if it's the first iteration ...

    // ... Or last iteration

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

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