Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

664
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda