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
CodePudding user response:
Change this
return view('pizza', $edibles);
To this
return view('/pizza', compact('edibles'));
CodePudding user response:
Route::get('/pizza', function(){
$edibles = [
'fruits' => 'Apple',
'beverage' => 'Milo',
'soup' => 'Egusi',
'drink' => 'cocacola',
];
return view('pizza', compact('edibles'));
});
CodePudding user response:
You can use compact to send the data. Try this for your case:
return view('pizza', compact('edibles'));