Laravel 无法使用with方法发回数据

Laravel 无法使用with方法发回数据,laravel,Laravel,伙计们,我正在重定向回一个带有变量的路由,但如果我死了,我会在视图中不断得到未定义的变量转储记录变量。这是我的密码 public function postSearchPatientMedicalRecords(Request $request){ $this->validate($request,[ 'patientReg'=>'required|present|exists:patient,patient_id' ]);

伙计们,我正在重定向回一个带有变量的路由,但如果我死了,我会在视图中不断得到未定义的变量转储记录变量。这是我的密码

public function postSearchPatientMedicalRecords(Request $request){
        $this->validate($request,[
           'patientReg'=>'required|present|exists:patient,patient_id'
        ]);
        $patient = Patients::where('patient_id','=',$request->input('patientReg'));
        $records = $patient->first()->myRecords()->orderBy('records.created_at','desc');
        return redirect()->route('records')->with('record',$records);
    }

您不需要重定向搜索结果。可以在代码下呈现搜索结果模板以显示搜索结果。 但是,例如,你必须为get和post设计路线

Route::match(array('GET','POST'),'login', 'AuthController@login');

您可以只重定向id或任何消息,但使用会话闪存可一次性使用。

要重定向回,您可以使用

return redirect()->back()->with('record',$records);
并使用

Session::get('record')

将记录更改为内部记录,如下所示

return redirect()->route('records')->with('records',$records);

你能显示视图和整个错误吗?试试这个
returnredirect('records')->with('record',$records)
在blade
{{session('record')}}}
中使用此选项,您可以将记录id传递给route。大多数情况下,laravel 5升级到8时都会发生这种情况……这正是我第一次尝试的,但仍然是同一个问题,它一直在说未定义变量record,并且我使用with方法发送它。您可以展示您的blade如何访问变量@spartyboy吗