Laravel 5.2 - 刀片 - 如何在 @each() 中获取迭代密钥


Laravel 5.2 - Blade - How to get the iteration key inside of an @each()

所以我正在尝试在视图中使用@each Laravel Blade方法,但我确实需要当前的迭代。显然,在@foreach中,我只会做$key => $value并使用$key。知道这是否可以用@each完成吗?

你可以看看引擎盖下:

https://github.com/illuminate/view/blob/master/Factory.php#L266(第 266 行)

只是一个猜测,但根据源代码,您可以尝试:

@each ('show.names', $names, 'name');

并在部分:

echo $key; // or $name['key'] or $name->key...

或者尝试dd($name)并在结果中查找密钥。