我有代码做一个返回重定向如下
public function addWarrent(Request $request)
{
$add_warrent = new WarrentModel();
$add_warrent->id_warrent = $request->input('id_warrent');
$add_warrent->workunit_id = Auth::user()->workunit_id;
$add_warrent->warr_name = $request->input('warr_name');
$add_warrent->warr_position = $request->input('warr_position');
$add_warrent->warr_category = $request->input('warr_category');
$add_warrent->warr_status = "Belum Diproses";
$add_warrent->warr_dt = Carbon::now();
$add_warrent->warr_tm = Carbon::now();
$add_warrent->save();
Excel::import(new WarrentItemImport, request()->file('warrent_item'));
$warrent_entry_id = WarrentItemModel::where('warrent_entry_id', null)
->update([
'warrent_entry_id' => $request->id_warrent,
]);
$add_head_workunit = WorkunitModel::where('id_workunit', Auth::user()->workunit_id)
->update([
'workunit_head_nip' => $request->workunit_head_nip,
'workunit_head_name' => $request->workunit_head_name
]);
$id = $request->input('id_warrent');
return redirect('satker/print_warrent', compact('id'))->with('success','Berhasil Membuat Surat');
}
然后,我得到了一个错误信息
参数2传递给Symfony 组件 HttpFoundation RedirectResponse: __construct()必须的是int类型的,数组给定,被调用D: XAMPP仓库根 供应商 laravel framework src 照亮 Redirector.php路由第233行
为什么会发生?
尝试以下选项之一
return redirect('/satker/print_warrent/' . $id)->with('success', 'Berhasil Membuat Surat.');
或
return redirect()->route('/satker/print_warrent/')
->with(compact('id'))
->with('success','Berhasil Membuat Surat');;
或
return redirect()->route('/satker/print_warrent/')
->with('id', $id)
->with('success','Berhasil Membuat Surat');;