Issue with axios DELETE on laravel resource controller


#1

I’m sending a DELETE rquest to my resource controller but for some reason my payload is not being sent:

deleteBulletin({ commit }, bulletin) {
        commit( 'SET_LOAD_STATUS', 1 );
        axios.delete("/bulletins"+bulletin.id, bulletin)
        .then((response) => {
            console.log(response.data.bulletin);
            commit( 'SET_LOAD_STATUS', 2 );
        }, 
        (error) => {
            console.log(error)
            commit( 'SET_LOAD_STATUS', 3 );
        })
    },

For some reason my payload is not being sent to the backend, however when I add delete route and chanfe method to POST the record correctly deletes from database, what’s the reason for this?

deleteBulletin({ commit }, bulletin) {
        commit( 'SET_LOAD_STATUS', 1 );
        axios.post("/bulletins/delete", bulletin)
        .then((response) => {
            console.log(response.data.bulletin);
            commit( 'SET_LOAD_STATUS', 2 );
        }, 
        (error) => {
            console.log(error)
            commit( 'SET_LOAD_STATUS', 3 );
        })
    },

My routes:

//bulletin routes
Route::resource('/bulletins','BulletinController');
Route::post('/bulletins/send-bulletin', 'BulletinController@sendBulletin');
Route::post('/bulletins/delete', 'BulletinController@delete');

#2

Axios’ delete method doesn’t support payloads. You can send it through config.data if you need. https://github.com/axios/axios/issues/897#issuecomment-343715381