Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mutaz's avatar
Level 7

Send curl request by Laravel Controller

Hi everyone! How can I send curl request by laravel controller, I need useful resource to understand and do that...

0 likes
3 replies
LaryAI's avatar
Level 58

To send a curl request from a Laravel controller, you can use the GuzzleHttp package. Here's an example:

  1. Install GuzzleHttp package using composer:
composer require guzzlehttp/guzzle
  1. 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/

tisuchi's avatar

@mutaz Do you really need to send a curl request from the controller?

I think it's not a good idea to call curl from the controller. If you do so, which means your controller depends on a third-party application (where you send the curl request). If the third-party app takes 30 seconds to response, that means your controller is hung up for that 30 secs.

Please or to participate in this conversation.