simon volk
simon volk

Reputation: 31

Laravel 5 MethodNotAllowedHttpException PUT

I am trying to update a user, but when I hit the submit button, Laravel throws the below error:

"RouteCollection->methodNotAllowed(array('GET', 'HEAD', 'POST')) in RouteCollection.php line 206".

I think that the PUT method is not allowed, but I do not understand the reason. The request never reaches UserController@update.

I have configured a resource route like this:

Route::resource('backend/users', 'Backend\UsersController');

The output of php artisan route:list is:

output of php artisan route:list

Upvotes: 2

Views: 9430

Answers (3)

allen
allen

Reputation: 90

I solved the problem like this: it must be the form's post action error;

<form method="POST" action="10.241.229.1/backend/users/{{$user->id}}"; accept-charset="UTF-8">

add the id you want update to the action.

enter image description here

Upvotes: 4

Giorgio Ghiatis
Giorgio Ghiatis

Reputation: 2130

Coming a bit late on this question.

In my experience this kind of error comes for two reasons:

  1. as Laravel docs say, HTML forms do not support PUT, PATCH or DELETE actions. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form.

  2. if you are making the request from a HTML form, and you have the VerifyCsrfToken middleware enable, than you will need to add a hidden _token field to the form with {{ csrf_token() }} as value.

Upvotes: 0

Imtiaz Pabel
Imtiaz Pabel

Reputation: 5443

use put method like this within form,for more https://laravel.com/docs/5.2/routing#form-method-spoofing

{{ method_field('PUT') }}

Upvotes: 1

Related Questions