Route::get('/pizza', function () {
$edibles = [
'fruits' => 'Apple',
'beverage' => 'Milo',
'soup' => 'Egusi',
'drink' => 'cocacola',
];
return view('pizza', $edibles);
});
@foreach ($edibles as $data)
{{ $data }}
@endforeach
It has been saying
Undefined
ErrorException
PHP 8.1.6
9.42.2
Undefined variable $edibles
4
Answers
Change this
To this
You can use compact to send the data. Try this for your case:
There is two way to send backend data to front end.
Here you can set a key name of passing data like ediblesData and get on front side with same name inside foreach loop.
Ex:
return view('pizza', ['edibles' => 'edibles']);
Here you cannot set a key name of passing data and you need to get same key name on front end side.
Ex:
return view('pizza', compact('edibles'));