To get around this error, I did the following, including adding the { after the @if. WTH?
@foreach ($days as $day => $meetings)
<pre></pre>
@if (!$loop->first) {
</div>
@endif
@endforeach
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi folks,
I'm getting this error on the following code
@foreach ($days as $day => $meetings)
@if (!$loop->first)
</div>
@endif
@endforeach
However, if I put raw HTML after the @foreach, all is well. Why is this? FWIW, I'm finding Laravel to be very picky at least when it comes to views.
I appreciate the help! Rob
I found the source of the problem, even though it shouldn’t be a problem. I looked at the cache file that Laravel produces which is an expansion of all the @ functions like if, foreach, etc. Some were not expanded. Those that weren’t, were followed by a PHP statement in the form of @php( line_of_php_code_here ). While this is a documented Laravel view statement, it doesn’t work. I substituted that for <?php line_of_php_code_here; ?> and all is well.
Can anyone tell me why @phhp() statements do not work as advertised?
Please or to participate in this conversation.