To send a curl request from a Laravel controller, you can use the GuzzleHttp package. Here's an example:
- Install GuzzleHttp package using composer:
composer require guzzlehttp/guzzle
- In your controller method, create a new GuzzleHttp client and use it to send a GET request to a URL:
use GuzzleHttp\Client;
public function sendCurlRequest()
{
$client = new Client();
$response = $client->request('GET', 'https://example.com/api');
$statusCode = $response->getStatusCode();
$body = $response->getBody()->getContents();
// Do something with the response
}
You can modify the request method, URL, headers, and body as needed. For more information on using GuzzleHttp, check out the official documentation: https://docs.guzzlephp.org/en/stable/