Peter Griffin
Peter Griffin

Reputation: 300

Laravel MethodNotAllowedHttpException......again

I have an update form and when I save I get this error message

(1/1) MethodNotAllowedHttpException in RouteCollection.php (line 251)

at RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in

RouteCollection.php (line 238)

Here is my form

<form enctype="multipart/form-data" action="{{route('products.update', $product->ProductId)}}" method="POST">
    {{ method_field('PUT') }}
    {!! csrf_field() !!}

and my routes

Route::get('products', 'ProductController@index')->name('products.index');
Route::post('products', 'ProductController@index')->name('products.search');
Route::get('products/create', 'ProductController@create')->name('products.create');
Route::post('products/create', 'ProductController@store')->name('products.store');
Route::get('products/{id}', 'ProductController@show')->name('products.show');
Route::get('products/{id}/edit', 'ProductController@edit')->name('products.edit');
Route::post('products/{id}/edit', 'ProductController@update')->name('products.update');

The routes list looks fine except the update route whereas other updates routes use PUT|PATCH

| | POST | products/{id}/edit products.update | \Http\Controllers\ProductController@update | web,auth

As far as I can see everything should work so why is the method not updating?

Upvotes: 0

Views: 336

Answers (1)

lagbox
lagbox

Reputation: 50491

You declared your route as POST.

Then in the form you spoof the PUT method.

POST != PUT.

The route is not defined to handle the method PUT. The method you define is the method that has to be used.

Upvotes: 0

Related Questions