Php 未识别Laravel 5变量

Php 未识别Laravel 5变量,php,laravel,variables,laravel-5,routing,Php,Laravel,Variables,Laravel 5,Routing,这是一个奇怪的问题,可能是因为我发现我的脚拉维尔 我有一个编辑页面,可通过以下方式访问: Route::get('editRow/{id}', function($id){ $section = App\Section::where('id', $id)->with('panels')->first(); return view('front.editrow',['thesection'=>$section]); }); 然后填写此表格,并使用longish方

这是一个奇怪的问题,可能是因为我发现我的脚拉维尔

我有一个编辑页面,可通过以下方式访问:

Route::get('editRow/{id}', function($id){
    $section = App\Section::where('id', $id)->with('panels')->first();
    return view('front.editrow',['thesection'=>$section]);
});
然后填写此表格,并使用longish方法发送给控制器,以更新表格,并以以下内容结束:

return view('front.editrow',['message'=>'update successful','id'=>$request->id]);
数据库更新正常。最初我遇到一个错误,所以我复制了路线,并将其从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

我感到困惑,并将非常感谢这个谜被解决

确保始终将节变量传递给视图

当您这样做时:

return view('front.editrow',['message'=>'update successful', 'id'=>$request->id]);
未提供此变量。您需要在视图中提供它,或者在刀片模板中检查它是否存在,方法是:

@if(isset($thesection)
  // whatever you want to do with the section
@endif

确保始终将节变量传递给视图

当您这样做时:

return view('front.editrow',['message'=>'update successful', 'id'=>$request->id]);
未提供此变量。您需要在视图中提供它,或者在刀片模板中检查它是否存在,方法是:

@if(isset($thesection)
  // whatever you want to do with the section
@endif