Laravel foreach in blade template overiding variables.
It changes the variable $user after the name has been used in foreach block, while this is not in pure PHP and other systems.
{{ $user['username'] }}
@foreach ($followers as $user)
{{$user['username']}}
@endforeach
{{ $user['username'] }}
1, Define a array called $followers and a $user
$data = [
"user"=>["username"=>"original_name"]
"followers" => [
["username"=>"new_name"]
]
];
2, Paint it to template
PHP foreach (which is used under the hood) has the same behaviour. You must use another name for foreach variable.
Yes, my fault. And I hate this behavior. 馃槶
Most helpful comment
PHP foreach (which is used under the hood) has the same behaviour. You must use another name for foreach variable.