未定义的变量:vaccine_feed(视图:C:\xampp\htdocs\webapp\resources



尝试将数据从控制器传递到数据库的视图时,我遇到了一个未定义的变量。

Part of my Controller:
public function index()
{
$vaccine_feed = Vaccines::All();
return view('welcome', [
'vaccines' => $vaccines,
'user' => $user,
'vaccine_feed' => $vaccine_feed
]);
}


View:
foreach($vaccine_feed as $vaccines ) {
}

我在下面添加了我的路线,如果这有帮助的话

Auth::routes();
Route::get('/', function () {
return view('welcome');
});
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/logout', function () {
Auth::logout();
Session::flush();
return view('welcome');
});

Route::get('/addstock', 'AddForm@getStockForm');
Route::post('/addstock', 'AddForm@postStockForm');

您是否在欢迎模板中包含addstock.blade.php。由于该视图具有不同的范围,因此您可能希望将 $vaccine_feed 传递到所包含的任何位置。

在控制器中尝试 dd($vaccine_feed)(在返回之前),看看它是否返回任何内容。

相关内容

最新更新