This is error says. Im inserting an static value for now in controller to check if the controller is okay. the code is below
protected function methodNotAllowed(array $others)
{
throw new MethodNotAllowedHttpException($others);
}
//IM JUST inserting static value for now to be able to check if inserting
DataController
public function update(Request $request, $name=null)
{
$insert = new leave([
'bio_id' => '10258',
'vacation_balance' => '25',
'sick_balance' => '25'
]);
$insert->save();
return view('pages/admin/data');
}
Route web.php
Route::post('admin/pages/admin/data', 'Admin\DTRDataController@update');
data.blade.php
<form action="{{url('admin/pages/admin/dtrdata')}}" method="post">
{{ csrf_field() }}
<input type="hidden" name="_method" value="PATCH">
<input type='text' class='total_undertimes' name='total_undertimes' id='total_undertimes' style='width:70px' />
<input type="submit" class="btn btn-primary" value="Edit" />
</form
What is ther error in my code
Remove
<input type="hidden" name="_method" value="PATCH">
line from your view. This makes your FORM submitted as PATCH method.
FYI: methodNotAllowed exception throws when request using wrong method. Ex:) When u POST to URL that is configured as GET in your Route file. In your situation you are requesting POST url using PATCH method.
You are showing the route for the URI admin/pages/admin/data
but your form is going to admin/pages/admin/dtrdata
. I am not sure what that 'dtrdata' URI is but it doesn't accept the PATCH
method.
admin/pages/admin/data != admin/pages/admin/dtrdata
Your Form Url and route are different :
route : admin/pages/admin/data
form : admin/pages/admin/dtrdata
you need to do two correction in your code.
your Form Url and route are different :
methodNotAllowed this error you got because you have submit form using patch method and you define post method in route. so should be used
Route::patch('admin/pages/admin/data', 'Admin\DTRDataController@update');
instead of
Route::post('admin/pages/admin/data', 'Admin\DTRDataController@update');
Route::patch('admin/pages/admin/data', 'Admin\DTRDataController@update');