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

naresh-io's avatar

PUT/PATCH request not getting the request payload

I'm facing some issue with Laravel-vuejs/axios PUT and PATCH requests. Actually the PUT/PATCH request are working when I run the project in localhost. But when I tried the same project in hosting server, I don't know why only these two requests are not working. Remaining methods GET/POST/DELETE are working as expected. But when I perform PUT/PATCH request to my server, in my controller I'm not receiving any data sent from vue/axios request.

My code

axios request from vue component

export const updateItem = ({ commit, dispatch }, payload) => {
    return axios.put('items/' + payload.id, payload).then((response) => {
            return Promise.resolve(response)
        })
}

web.php

Route::put('/items/{item}', 'ItemController@update')->name('items.update');

ItemController

public function update(Request $request, Item $item)
{
    try {
        $item->update([
            'name' => $request->name,
            'price' => $request->price,
        ]);
    } catch (QueryException $e) {
        return $e->errorInfo;
    }
 
    return response()->json($item, 200);
}
0 likes
4 replies
kreierson's avatar

try putting a / before items in your axios request?

export const updateItem = ({ commit, dispatch }, payload) => {
    return axios.put('/items/' + payload.id, payload).then((response) => {
            return Promise.resolve(response)
        })
}
kreierson's avatar

Is there another route above this route that maybe has the same path and that route is getting hit first? Just a thought, I run into this all the time.

Route::patch('/items/{item}', 'ItemController@someMethod'); //This will get hit first

Route::resource('/items', 'ItemcontrollerApi'); //This will also get hit before the put request

// move this line above the two before this
Route::put('/items/{item}', 'ItemController@update')->name('items.update');
1 like
iamstilinski's avatar

This is a known problem that has been around since Laravel 5.x, I'm not exactly sure why this is happening but a workaround is to change your request type to POST and add a _method field with the value put, Laravel automatically recognizes that as a PUT request. If you are using axios, it'd be within your formData, try to append that value through formData.append('_method', 'put'); and change your axios request to post.

Please or to participate in this conversation.