I'm working with Laravel 5.8 and I have this syntax:
@php($counter_foreach = 0)
@foreach($memnames as $mem=>$memname)
@php
@endphp
@endforeach
Now when I run this, I get syntax error, unexpected 'endforeach' (T_ENDFOREACH) error:
But when I remove @php @endphp, and replace it with html, the error will be gone!
So what's going wrong here?
Is there anything wrong about using @php after @foreach in Laravel Blades?

Try to add @endphp everytime you add @php like this: