How to Http Curl Delete Request in Laravel?

Laravel 8 , Laravel 7 , Laravel , Laravel 6

Nicesnippets

658

31-07-2021


Hi Guys,

In this example,I will leran you how to http curl delete request in laravel.you can easy and simply http curl delete request in laravel.

This article goes in detailed on laravel http request delete parameters. i explained simply about 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.

Install guzzlehttp/guzzle Package:


you have to install guzzlehttp/guzzle composer package in your project:

composer require guzzlehttp/guzzle

Example 1:

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Http;

class TestController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$deleteID = 10;

$apiURL = 'https://api.nicesnippets.com/api/users/'. $deleteID;

$response = Http::delete($apiURL);

$statusCode = $response->status();

$responseBody = json_decode($response->getBody(), true);

dd($responseBody);

}

}

Output:

Array

(

[message] => User Id: 10 Delete Successfully

)

Example 2:

namespace App\Http\Controllers;

class TestController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$deleteID = 10;

$apiURL = 'https://api.nicesnippets.com/api/users/'. $deleteID;

$client = new \GuzzleHttp\Client();

$response = $client->request('DELETE', $apiURL);

$statusCode = $response->getStatusCode();

$responseBody = json_decode($response->getBody(), true);

dd($responseBody);

}

}

Output:

(

[message] => User Id: 10 Delete Successfully

)

It will help you...