Laravel Http Curl Delete Request Example

By Hardik Savani April 16, 2024 Category : Laravel

Hi,

In this example, i will show you laravel http curl delete request example. i explained simply about laravel curl delete request example. This article goes in detailed on laravel http request delete parameters. i explained simply about how to call curl delete request in laravel.

Here, i will give you two examples of how to call curl delete request with laravel GuzzleHttp. first example will with http and second example with GuzzleHttp. so let's see both examples one by one here. you can easily use this example with laravel 6, laravel 7, laravel 8, laravel 9, laravel 10 and laravel 11 version.

Install guzzlehttp/guzzle Package:

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

composer require guzzlehttp/guzzle

Example 1:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\Http;

class ITSController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index()

{

$deleteID = 2;

$apiURL = 'https://api.mywebtuts.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

)

Example 2:

<?php

namespace App\Http\Controllers;

class ITSController extends Controller

{

/**

* Write code on Method

*

* @return response()

*/

public function index2()

{

$deleteID = 2;

$apiURL = 'https://api.mywebtuts.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

Array

(

[message] => User Id: 2 Delete Successfully

)

i hope it can help you...

Tags :
Shares