Undefined variable $loop in Laravel Blade loop

佐手、 提交于 2019-12-23 17:50:39

问题


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!


回答1:


After upgrading to Laravel 5.3, you'll need to re-save your views in order to see the $loop variable take effect as you may be viewing the cached versions. I had the same issue, upgraded, still had the issue, re-saved the view (after modifying) and then $loop worked.



来源:https://stackoverflow.com/questions/39566997/undefined-variable-loop-in-laravel-blade-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!