Support the ongoing development of Laravel.io →
posted 7 years ago
Views Blade
Last updated 2 years ago.
0

I had the exact same issue.

@foreach($topics as $topic)
  {{ $topic->title }}
@endforeach

{{ $topic->id }} // <- this should fail but $topic remains set

I later found out that this is not a Blade issue but an issue with PHP itself. If you have a PHP foreach loop the variable for a single item, of the array you are looping trough, will be available after the loop and it will be set to the last item of the array.

Last updated 6 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

zero zero Joined 4 May 2017

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.