jeudi 8 novembre 2018

Why redirect in controller does not link to right path?

I want to redirect a page when a button 'add new' clicked using this code in controller:

return redirect()->action('Modul\ProfilController@show', ['id' => $id]);

It should return to this page with url

http://127.0.0.1:8000/view_profil/3 <-- {id}

The route for view_profil page is:

Route::get('/view_profil/{id}', 'Modul\ProfilController@show')->name('viewProfil');

However, it return as this url, without id value:

http://127.0.0.1:8000/view_profil

Why it doesn't retrieve the $id value?

This is the controller code:

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]);
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire