Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

652
Views
DELETE method with request body in axios and laravel

I try to delete backup with DELETE method in Laravel and Axios but the request is comming back empty.

Controller

     /**
     * Remove the specified resource from storage.
     * @param Request $request
     */
    public function destroy(Request $request)
    {
        return $request->all();
    }

Route

Route::middleware(['auth'])->prefix('backup')->group(function() {
    Route::get('/', 'BackupController@index');
    Route::delete('/delete', 'BackupController@destroy')->name('backup.delete');
});

Axios Request

axios.delete(`/backup/delete`,{data: {filename: filename}} )
.then((response)=>{
      console.log(response.data)
   })
.catch((err) => console.error(err.response.data.errors));

Console.log(response) enter image description here

What is the problem with my code?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You send over axios the the filename. Then you have fetch in the destroy method the filename and get the model from the database.

Route

Route::delete('api/delete/{filename}', BackupController@destroy')->name('backup.delete');

Controller

$model = App\Models\Backup::where('filename', $request->filename)::first();
$model->destroy();

Update

Sending the parameters via the body using the DELETE method is not recommended. Some servers do not support it. However.

  1. Change the method from delete to put or POST
axios.put(`/backup/delete`,{data: {filename: filename}} )
.then((response)=>{
      console.log(response.data)
   })
.catch((err) => console.error(err.response.data.errors));
  1. Adjust your Route
Route::delete('/delete', 'BackupController@destroy')->name('backup.delete');

Then you can fetch in your Controller over the Request Object the parameter (filename).

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!