Home:ALL Converter>Undefined variable $loop in Laravel Blade loop

Undefined variable $loop in Laravel Blade loop

Ask Time:2016-09-19T14:52:03         Author:SeKra

Json Formatter

according to the latest laravel blade documentation (https://laravel.com/docs/5.3/blade see "loops") I can "[...] use the loop variable to gain valuable information about the loop[...]".

My laravel version is up to date but inside my foreach loop I can't access the $loop variable. It says "undefined variable $loop".

Example:

@foreach( $values["rating"] as $rating )
@if( $loop->iteration == 3 )
-- do something --
@endif
@endforeach

Does anyone know a solution for this? Thank you so much!

Author:SeKra,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/39566997/undefined-variable-loop-in-laravel-blade-loop
yy