Getting the iteration index in Laravel's render_each function
With Laravel's render_each function you can display each item in an array using a partial. This is very handy if you display blog posts or a list of items in a shopping cart.
If you need to access the index of the current iteration, you can easily access it in your partial through the $key variable.
Example
application/views/myview.blade.php
<div class="posts">
{{render_each('partials.post', $posts, 'post')}}
</div>
application/views/partials/post.blade.php
<div class="post">
Iteration index: {{$key}}
</div>
If you heard of Laravel for the first time, you should definitely check it out at http://laravel.com. It is a nice PHP framework for web applications and makes developing such apps a breeze.
Written by Björn Kaiser
Related protips
Have a fresh tip? Share with Coderwall community!
PHP applications still send a browser full of JavaScript. Hardening the server does not inventory the payment, analytics, and plugin scripts that run after the HTML is delivered.
Security insights from Cside