How to get key in a foreach loop to work using blade

 foreach in Blade works the same as a regular PHP foreach. You should be able to do something like:

@foreach ($nodes as $node)
    <li>{{ $node->url }}</li>
@endforeach

If you need access to the array key value for each node:

@foreach ($nodes as $key => $node)
    <li>{{ $key }}: {{ $node->url }}</li>
@endforeach

Posted

in

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *