未定义的变量:vaccine_feed(查看:C:\ xampp \ htdocs \ webapp \ resources \ views \ addstock.blade.php)

问题描述 投票:-1回答:2

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

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');
php laravel
2个回答
0
投票

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


-1
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.