vendredi 9 novembre 2018

Why parameter from form not passed to controller in laravel?

I want to submit a form with a parameter to store controller by having this code at the form:

       {!! Form::open(['method' => 'POST', 'action' => ['Modul\KeluargaController@store', $getItemregistration->ItemRegistrationID]]) !!}

Then, I retrieve the parameter in store controller:

  public function store(Request $request, $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()->route('viewProfil', ['id' =>$id]);

    else

        return redirect()->route('viewProfil', ['id' =>$id]);
}

The route for keluarga controller are as follows:

    //keluarga utama
Route::resource('keluarga', 'Modul\KeluargaController');

//view maklumat keluarga
Route::get('/view_keluarga/{id}', 'Modul\KeluargaController@show')->name('viewKeluarga');

//add maklumat keluarga kakitangan
Route::post('/add_keluarga/{id}', 'Modul\KeluargaController@create')->name('addKeluarga');

//edit maklumat keluarga kakitangan
Route::get('/edit_keluarga/{id}', 'Modul\KeluargaController@edit')->name('editKeluarga');

//delete ahli keluarga
Route::get('/delete_keluarga/{id}', 'Modul\KeluargaController@destroy')->name('deleteKeluarga');

However, the problem is it produce this error when submit the form:

Type error: Too few arguments to function App\Http\Controllers\Modul\KeluargaController::store(), 1 passed and exactly 2 expected

Looks like the $id parameter is not received from $getItemregistration->ItemRegistrationID value in form::open.

What am I missing here?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire