Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

aletopo's avatar
Level 34

PUT method not working on API

When i use a specific request (example: StorePostRequest) and then try to update with PUT method, always throws an "Method not allowed" exception. It is ok ? The route:list command shows the "PUT posts" route. I can't understand why is wrong.

0 likes
10 replies
Nash's avatar

"Method not allowed" means that you are trying to use the wrong HTTP request method on that route, e.g. sending a GET or POST request to a route that is expecting PUT.

Can you show the code for how you are trying to do this request?

StefanJanssen's avatar

Assuming you are just using an HTML form

<form method="POST" action="http://example.com/home/" accept-charset="UTF-8">
    <input type="hidden" name="_method" value="PUT" />
    <!-- The rest of your form -->
</form>

Since the HTML form cannot handle method="PUT" you would need to use method="POST" and the hidden input field with the name _method and as value you can use: DELETE, PUT, PATCH (and the other request methods if I forgot any of them).

1 like
Snapey's avatar

You can also get this issue if your route expects a parameter and you don't pass it, or you pass a parameter and there is no place for it in the route.

2 likes
aletopo's avatar
Level 34

I have not html form because it will be consumed by another php script via Guzzle or similar. Actually i am using Postman. It works fine with validation on controller, but fails just when uses specific request like "App\Requests\StorePostRequest".

1 like
StefanJanssen's avatar

Can you share your StorePostRequest code and the data you are trying to submit?

1 like
aletopo's avatar
Level 34

This the code, very basic, like all tutorials...

class StorePostRequest extends FormRequest
{
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'title' => 'required|between:3,255',
        ];
    }
}
1 like
aletopo's avatar
Level 34

Ok Snapey! I tried both:

Route::resource('posts', 'PostController');
Route::put('PostController', 'create');
Snapey's avatar

try

Route::put('posts', 'PostController@create');

and temporarily comment out any resource route for posts.

You might find it a lot less hassle to just use POST even though its not strictly RESTful

3 likes

Please or to participate in this conversation.