show the code...
405 Method Not Allowed
I am building an new web app with Laravel 6.3. I am testing the small API I have built. I tested a get all, get one, and create requests but I have run into an issue with the put/patch request.
Here are my routes in api.php
Route::prefix('room')->name('room.')->group(function () {
Route::get('/', 'RoomController@index')->name('index');
Route::get('/{room}', 'RoomController@show')->name('show');
Route::post('/', 'RoomController@store')->name('store');
Route::put('/{room}', 'RoomController@update')->name('update');
Route::delete('/{room}', 'RoomController@delete')->name('delete');
});
when I make a put request to example.com/api/room/3 and i get a 405 Method Not Allowed: The PUT method is not supported for this route. Supported methods: GET, HEAD.
If I change the request to a patch request I get the same thing. If I set the request to patch in api.php and send a put request I get 405 Method Not Allowed: The PUT method is not supported for this route. Supported methods: GET, HEAD, PATCH, DELETE. Which I expect. I change the request to a patch request and i get a 405 Method Not Allowed: The PUT method is not supported for this route. Supported methods: GET, HEAD.
Whats going on here?
I found the issue. I send my data with a multipart form body. This was working for post but it seems the data was not being sent causing an issue with validation which then causes the routing issue.
I switched it to JSON body and now it works. My guess is there is an issue when validation fails for an item that was not sent with the payload.
Please or to participate in this conversation.