When I use Laravel blade file foreach loop, the variable is accessible after the foreach loop, whereas the scope of the variable should be only within the loop
@foreach($user->referral as $ref)
<tr>
<td>{{ $ref->referral_amount }}</td>
<td>{{ $ref->status }}</td>
</tr>
@endforeach
$ref
: This variable is accessible outside endforeach loop after @endforeach
Alexey Mezenin :
From the foreach docs:\n\nWarning\nReference of a $value and the last array element remain even after the foreach loop. It is recommended to destroy it by unset()\n\nSo, if you want to destroy the reference, do this:\n<?php unset($ref); ?>\n\nOr:\n@php unset($ref); @endphp\n",
2018-02-26T11:41:29
Maitri Patel :
It is recommended to destroy it by unset()\n\n @php unset($ref); @endphp\n",
2018-12-18T07:17:20