Laravel MethodNotAllowedHttpException error en route Resource


I have a question, when I try to update a data I get the MethodNotAllowedHttpException error, I understand that this error comes out when there is a problem with the paths that are get and should be post but in my case my path is resource :


Route::resource('inventario', 'InventarioController');

Controller (update function)

   public function update(Request $request, $id)
       $this->validate($request,[ 'cantidad'=>'required']);
       return redirect()->route('')->with('success','Registro actualizado satisfactoriamente');

Vista (show.blade.php)

<form method="POST" action="{{ route('inventario.update', $inv->id_inventario )}}" role="form">
     {{ csrf_field() }}
     <div class="form row">
         <input type="hidden" name="id_inventario" class="form-control input-sm" id="id_inventario"
                                   value="{{ $inv->id_inventario }}">
         <input type="number" name="cantidad" class="form-control input-sm" id="cantidad"
                                   value="{{ $inv->cantidad }}">
     <div class="form-group col-md-6">
         <input type="submit" value="Guardar" class="btn btn-success">
         <button type="button" class="btn btn-white" data-dismiss="modal">Cerrar</button>


In my case when clicking on the update button, a modal opens, which is where the data I want to update appears.

asked by Daniel Gironás 04.12.2018 в 06:33

1 answer


In your view, your form should contain the following to indicate that it is an update action.


This verb PUT will serve to indicate that it is an update action; this goes on your form; since in the forms; The only methods that can be specified are POST and GET

Now you should declare the route separately, in order to distinguish one action from the other

Route::put('/inventario', '[email protected]');

The previous route should go just before the declaration of your ResourceController ; As you can see at the end with the operator @ I indicate the name of the method I want to access, in this case the% of update

answered by 04.12.2018 / 06:45