[英]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.