当我使用控制器中的以下代码单击“添加新”按钮时,我想重定向页面:
return redirect()->route('viewProfil', ['id' =>$id]);
它应该返回带有URL的页面
http://127.0.0.1:8000/view_profil/3 <-- {id}
view_profil页面的路由为:
Route::get('/view_profil/{id}', 'Modul\ProfilController@show')->name('viewProfil');
但是,它作为此URL返回,没有id值:
http://127.0.0.1:8000/view_profil
为什么不检索$ id值?
如果我将代码更改为此:
return redirect()->route('viewProfil', ['id' =>3]);
它将重定向到正确的页面。
这是控制器代码:
public function store(Request $request, Itemregistration $id)
{
$data = ['ItemRegistrationID' => $request->itemregistrationid,
'SectionID' => $request->sectionid,
'CategoryID' => $request->categoryid,
'familyname' => $request->familyname,
'kpfamily' => $request->kpfamily,
'No_tel' => $request->No_tel,
'Comments' => $request->Comments,
'KategoriFamID' => $request->kategori_family,
'majikan' => $request->majikan,
'ulasan' => $request->ulasan,
'PewarisID' => $request->kategori_pewaris,
'no_akaun' => $request->no_akaun,
'statusPengundiID' => $request->statuspengundi,
];
$itemregistrationkeluarga = DB::table('itemregistrationkeluarga')->insert($data);
if($itemregistrationkeluarga)
return redirect()->action('Modul\ProfilController@show', ['id' => $id]);
else
return redirect()->action('Modul\ProfilController@show', ['id' => $id]);
}