Laravel 5 CURL request using ixudra/curl package

Laravel 5 CURL request using ixudra/curl package

  • 14 July, 2018
  • Renish Khunt
  • Laravel
  • 202

Today we are going to learn the easiest way to sending Laravel 5 CURL request. We can easily send the CURL request using the ixudra curl package with fluent interface similar the Laravel query builder. The ixudra curl package using the CURL for sending the request.

We can send the curl request using PHP way like

        // create curl resource 
        $ch = curl_init(); 

        // set url 
        curl_setopt($ch, CURLOPT_URL, ""); 

        //return the transfer as a string 
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

        // $output contains the output string 
        $output = curl_exec($ch); 

        // close curl resource to free up system resources 

We are initialise CURL request set the URL for sending the CURL request getting the output form CURL Object then close CURL request. This way we can send the CURL request.

We are going to learn a new way of sending CURL request using ixudra curl package.

I hope you installed the Laravel if not please install using this article.

First of all, We are going to install ixudra curl package.

composer require ixudra/curl

After, Complete the package installation we are going to registering service provider and aliases on Laravel.

Let’s open “config/app.php” file for registering service provide and aliases like

'providers'     => array(
'aliases'       => array(
        'Curl'          => Ixudra\Curl\Facades\Curl::class,

The package is ready for use, Let’s see the example for sending the curl request using ixudra curl package.

Let’s see the example of sending the CURL request using ixuda package. First of all, We are going to create the route for the CURL example like


Now, Let’s create the “WordPressController” using below command.

php artisan make:controller WordPressController

That command help us for creating the controller file, Now, let’s open that controller file for CURL request like


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Ixudra\Curl\Facades\Curl;

class WordPressController extends Controller

    public function getPosts(){

        // Send a GET request to:
        $response = Curl::to('')

        echo '<pre>';

        // Send a GET request to:
        $response = Curl::to('')
        ->withData( array( 'search' => 'test' ) )

        // Send a GET request to: using JSON
        $response = Curl::to('')
        ->withData( array( 'search' => 'text' ) )



We can be sending the different type of request using ixudra curl package like GET, POST, PUT, PATCH, DELETE or else We can send the custom headers or content types. You can get more detail from here.


// Send a GET request to:
$response = Curl::to('')


// Send a POST request to:
$response = Curl::to('')


// Send a PUT request to:
$response = Curl::to('')


// Send a PATCH request to: 
$response = Curl::to('')  


// Send a DELETE request to:
$response = Curl::to('')

The ixudra package provides functionality we can set custom headers like

// Send a GET request to: with custom headers
$response = Curl::to('')
    ->withHeader('customheader: thecodingstuff')

We can easily send the CURL request using ixudra Laravel Package. If you face any issue write the comment below.