[英]undefined variable php laravel 5.4
i kept getting the same error, 我一直遇到同样的错误,
undefined variable: theaters on my blade, line 14.
未定义的变量:我的刀片上的影院,第14行。
here is my addcine.blade.php line 14 这是我的addcine.blade.php第14行
@foreach ($theaters as $theater)
<option value="{{ $theater->name }}"/>
@endforeach
here is my addcinemacontroller 这是我的addcinemacontroller
public function index(){
$theaters = Theater::all();
return view('schedules.addcine', compact('name'));
and my route 和我的路线
Route::get('addcinema','AddCinemaController@index');
});
It should be: 它应该是:
return view('schedules.addcine', compact('theaters'));
compact('theaters')
does exactly this: compact('theaters')
正是这样做的:
return view('schedules.addcine', ['theaters' => $theaters]);
return view('schedules.addcine', compact('theaters'));
您没有将$theaters
值发送给视图,
You are sending name
instead of theaters
in controller 您正在发送
name
而不是控制器中的theaters
public function index(){
$theaters = Theater::all();
return view('schedules.addcine', compact('theaters'));
You need to return the $thaters
variable to view so that you can use it there. 您需要返回
$thaters
变量进行查看,以便可以在其中使用它。
Return like this: 这样返回:
return view('schedules.addcine', compact('theaters'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.