[英]undefined variable php laravel 5.4
我一直遇到同樣的錯誤,
未定義的變量:我的刀片上的影院,第14行。
這是我的addcine.blade.php第14行
@foreach ($theaters as $theater)
<option value="{{ $theater->name }}"/>
@endforeach
這是我的addcinemacontroller
public function index(){
$theaters = Theater::all();
return view('schedules.addcine', compact('name'));
和我的路線
Route::get('addcinema','AddCinemaController@index');
});
它應該是:
return view('schedules.addcine', compact('theaters'));
compact('theaters')
正是這樣做的:
return view('schedules.addcine', ['theaters' => $theaters]);
return view('schedules.addcine', compact('theaters'));
您沒有將$theaters
值發送給視圖,
您正在發送name
而不是控制器中的theaters
public function index(){
$theaters = Theater::all();
return view('schedules.addcine', compact('theaters'));
您需要返回$thaters
變量進行查看,以便可以在其中使用它。
這樣返回:
return view('schedules.addcine', compact('theaters'));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.