3
I got the following foreach
in Laravel.
@foreach($values as $value)
<li>{{ $value }}</li>
@endforeach
I would like to add a special information when it comes to the first loop item.
In some other Engines template, there is usually a specific method to know which is the first or last item of the loop.
For example, the Twig:
{% for (value in values) %}
<li>{% if loop.first %}Primeiro - {% endif %}{{ value }}</li>
{% endfor %}
Is there any way to do this in Laravel?
+1, you are on top of the news. I was already thinking of answering :p
– Wallace Maxters
@Wallacemaxters was just playing with 5.3 :P
– Miguel
You may have other information that would be interesting to add to the question, such as that one. There are more things I imagined :D
– Wallace Maxters
Miguel, I’m going to do a search on Laravel 5.3. It was very good the answer. I’ll check which object he uses in the variable
$loop
, I’m a little suspicious that it’s some class that implements Recursiveiterator.– Wallace Maxters
Yap maybe it is, it’s true @Wallacemaxters
– Miguel