Error MethodNotAllowedHttpException in laravel

0

I'm trying to update data, however I get:

  

Symfony \ Component \ HttpKernel \ Exception \   MethodNotAllowedHttpException

My route:

Route::put('animalperdido/{id}', 'AnimalPerdidoController@update');

My role:

 public function update(Request $request, $id)
{
    $animalPerdido = AnimalPerdido::findOrFail($id);
    $animalPerdido->update($request->all());

    return $animalPerdido;
}

In postman I'm trying to pass in the header the id and in the body a key that should be changed.

    
asked by anonymous 10.12.2018 / 22:37

1 answer

2

You are trying to make a request different from what your route expects.

Routes.php

Route::put('animalperdido/{id}', 'AnimalPerdidoController@update');

Use the @method Blade directive in your HTML form

<form action="{{url('/animalperdido/ID_ANIMAL_PERDIDO')}}" method="post">
    @method('PUT')
    @csrf

    ...
</form>

See the documentation for more information: link

    
11.12.2018 / 17:25