Methodnotallowedhttpexception error in Laravel

Asked

Viewed 626 times

0

I’m trying to update data, but I get:

Symfony Component Httpkernel Exception MethodNotAllowedHttpException

My route:

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

My job:

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

    return $animalPerdido;
}

In Postman I am trying to pass in the header the id and in body a key that must be changed.

1 answer

2


You are trying to make a different request from which your route awaits.

Routes.php

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

Use the Blade directive @method in your HTML form

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

    ...
</form>

See documentation for more information: https://laravel.com/docs/5.7/controllers

  • I use the angled on the frontend, I only use the Laravel to create the API

  • but I understood the problem

Browser other questions tagged

You are not signed in. Login or sign up in order to post.