If my code is like this :
<ul class="test">
@foreach($categories as $category)
@if($loop->first)
$category_id = $category->id
@endif
@endforeach
</ul>
There exist error :
Undefined variable: category_id (View: C:\xampp\htdocs\myshopesources\views\front.blade.php)
If my code is like this :
<ul class="test">
@foreach($categories as $category)
@php
if($loop->first)
$category_id = $category->id
@endphp
@endforeach
</ul>
I works
Why the first way does not work?