I have a form request to update the data in database.
My Controller
public function edit($id)
{
//
$pinjaman = Pinjaman_Tanker::where('no_admin', $id)->firstOrFail();
return view('pinjaman.edit')->with('pinjaman', $pinjaman);
}
public function update(Request $request, $id)
{
//
$pinjaman = Pinjaman_Tanker::where('no_admin', $id)->firstOrFail();
$validation = Validator::make($request->all(),[
"tgl_input_pinjam" => "required|date",
"no_anggota" => "required",
"jumlah" => "required",
"kebutuhan" => "string|required",
"angsuran" => "required",
"termin" => "required"
]);
if ($validation->fails()){
return redirect()->back()->withErrors($validation->errors())->withInput();
}
$pinjaman -> tgl_input_pinjam = date('Y-m-d', strtotime($request->get('tgl_input_pinjam')));
$pinjaman -> kebutuhan = $request -> get('kebutuhan');
$pinjaman -> jumlah = preg_replace('/(?:[.]|\,00)/', '$1', $request->get('jumlah'));
$pinjaman -> angsuran = preg_replace('/(?:[.]|\,00)/', '$1', $request->get('angsuran'));
$pinjaman -> termin = $request -> get('termin');
$pinjaman -> save();
return redirect(url('pinjaman'));
}
Route
Route::get('pinjaman/{no_admin}/edit', 'Pinjaman\PinjamanController_Tanker@edit');
Route::put('pinjaman/{no_admin}', 'Pinjaman\PinjamanController_Tanker@update');
The view
<form id="edit_pinjaman" method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="_method" value="put">
<input type="hidden" name="_token" value="">
After I hit submit button, it didn't redirect to 'pinjaman' but show the form back with this error:
MethodNotAllowedHttpException in RouteCollection.php line 207:
in RouteCollection.php line 207
at RouteCollection->methodNotAllowed(array('PUT')) in RouteCollection.php line 194
at RouteCollection->getRouteForMethods(object(Request), array('PUT')) in RouteCollection.php line 142
at RouteCollection->match(object(Request)) in Router.php line 729
at Router->findRoute(object(Request)) in Router.php line 652
at Router->dispatchToRoute(object(Request)) in Router.php line 628
at Router->dispatch(object(Request)) in Kernel.php line 214
and so on
I already followed the guide in laravel 5.0 official documentation and do some research on internet. But this error keeps happening.
How i solve this?
Thank you
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3fSZSh7
via IFTTT
Aucun commentaire:
Enregistrer un commentaire