有点奇怪的问题,这可能是因为我正在寻找Laravel的脚。
我有一个编辑页面,通过以下方式访问:
Route::get('editRow/{id}', function($id){
$section = App'Section::where('id', $id)->with('panels')->first();
return view('front.editrow',['thesection'=>$section]);
});
然后,这个表单完成并进入一个带有较长方法的控制器来更新表,并以
结尾:return view('front.editrow',['message'=>'update successful','id'=>$request->id]);
数据库更新OK。最初我得到了一个错误,所以我复制了路由并将其从get更改为post:
Route::post('editRow/{id}', function($id){
$section = App'Section::where('id', $id)->with('panels')->first();
return view('front.editrow',['thesection'=>$section]);
});
虽然这是完全相同的参数等等我总是得到;
Undefined variable: thesection
我很困惑,非常感谢这个谜被解开!
确保 section变量总是传递给视图。
当你这样做的时候:
return view('front.editrow',['message'=>'update successful', 'id'=>$request->id]);
没有提供这个变量。您需要在视图中提供它,或者在刀片模板中检查它是否存在,使用:
@if(isset($thesection)
// whatever you want to do with the section
@endif