Answer the question
In order to leave comments, you need to log in
What is the correct way to write an array to a Laravel controller?
How to correctly write an array with associative keys as a Laravel controller parameter, so that later it can be passed to the viewer - {{ $arr['name'] }}, {{ $arr['age'] }}, {{ $arr['salary' ] }}?
Array example:
$arrUsers = [
["name" => "Вася"],
["age" => 33],
["salary" => 450]
];
Answer the question
In order to leave comments, you need to log in
In the controller
$users = [
[
"name" => "Вася",
"age" => 33,
"salary" => 450
]
];
return view('users', ['users' => $users]);
// или
return view('users', compact('users'));
@foreach ($users as $user)
{{$user['name']}}
@endforeach
The entire array must be inserted into the arr key. There's an export function under the hood
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question