How to Http Curl Delete Request in Laravel?
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...
- How to Notifications With database Driver in Laravel 11?
- How to Send Email Via Notification in Laravel 11?
- How to Install and Configure Laravel 11 Debugbar?
- How to Like Dislike System in Laravel 11?
- How to Paginate a Model with Relationship in Laravel 11?
- Laravel 11 Upload Files to Amazon S3 Example
- Laravel 11 Send WhatsApp Messages Example
- Laravel 11 Rest API Authentication Using JWT Tutorial