curl in laravel

Posted by w3diy - 6 months ago

curl in laravel : First of all, we have to add ixudra/curl package for run curl request method so one your cmd or terminal and fire bellow command:

composer require ixudra/curl

CURL Post Request:

public function fetchAllData()
{

    $response = Curl::to('https://domain-name.com/posts')
                ->withData(['title'=>'Test', 'body'=>'sdsd', 'userId'=>1])
                ->post();

    dd($response);

}

CURL Put Request:

public function fetchAllData()
{

    $response = Curl::to('https://domain-name.com/posts/1')
                ->withData(['title'=>'Test', 'body'=>'sdsd', 'userId'=>1])
                ->put();

    dd($response);

}

CURL Patch Request:

public function fetchAllData()
{
    $response = Curl::to('https://domain-name.com/posts/1')
                ->withData(['title'=>'Test', 'body'=>'sdsd', 'userId'=>1])
                ->patch();
    dd($response);
}

CURL Delete Request:

public function fetchAllData()
{
    $response = Curl::to('https://domain-name.com/posts/1')
                ->delete();
    dd($response);

}