How to Http Curl Delete Request in Laravel?

Share Me
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  
  •  

Today now in this post i will show an example of laravel http curl delete request. Now here i will explain this simply how to laravel curl delete request. So this article goes in a detailed on laravel http request delete parameters. Now here i will explain with you a example of how to call curl delete request in laravel.

Now here, i will give you two very simple examples of how to call curl delete request by using laravel GuzzleHttp. So at first example will with GuzzleHttp and the second example with Http.

So let’s see the both examples one by one here. Now we can easily use this example with any version of laravel 6, laravel 7 and laravel 8.

Install guzzlehttp/guzzle Package:

We need to install guzzlehttp/guzzle composer package in our project:

composer require guzzlehttp/guzzle

Example 1:

<?php
  
namespace App\Http\Controllers;
  
class COPController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $deleteID = 1;
        $apiURL = 'https://api.smallseospider.com/api/users/'. $deleteID;
              
        $client = new \GuzzleHttp\Client();
        $response = $client->request('DELETE', $apiURL);
   
        $statusCode = $response->getStatusCode();
        $responseBody = json_decode($response->getBody(), true);
  
        dd($responseBody);
    }
}
Array(    
[message] => User Id: 1 Delete Successfully
)

Example 2:

<?php
  
namespace App\Http\Controllers;
  
use Illuminate\Support\Facades\Http;
  
class COPController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $deleteID = 1;
        $apiURL = 'https://api.smallseospider.com/api/users/'. $deleteID;
  
        $response = Http::delete($apiURL);
  
        $statusCode = $response->status();
        $responseBody = json_decode($response->getBody(), true);
    
        dd($responseBody);
    }

}

Output

Array(   
 [message] => User Id: 2 Delete Successfully
)

Read Also: How to Mailchimp api integration in Laravel ?

Thanks for read. I hope it help you. For more you can follow us on facebook

About Shahriar Sagor

My name is Shahriar sagor. I'm a developer. I live in Bangladesh and I love to write tutorials and tips that will help to other Developer's. I am a big fan of PHP, Javascript, JQuery, Laravel, Codeigniter, VueJS, AngularJS and Bootstrap from the early stage.

View all posts by Shahriar Sagor →