Laravel CURL Request Example using ixudra/curl
https://www.itsolutionstuff.com/post/laravel-5-curl-request-example-using-ixudra-curl-packageexample.html
Laravel CURL Request Example using ixudra/curl
By Hardik Savani July 30, 2017 Category : PHP Laravel CURLIf you know about php curl then you can simply run get, post request and get data from url. php curl is very interesting things. if you know and use in with php then you have to do curl_ini(), curl_setopt(), curl_exec() and curl_close() etc that way we can simply run request.
But, If you require to fire curl request in laravel 5 application then you don't require to do curl_init(), curl_close() etc. We can run request very easily and get response in json. so we will use ixudra/curl composer package for run curl request very simple.
Using ixudra curl package you can very simply curl post request in laravel, curl get request in laravel, curl put request in laravel, curl delete request in laravel etc. So here you can also set header, data etc. Here first i will install package on laravel application then we will give you very simple example to get json data. So let's just follow bellow example:
Install ixudra/curl Package:
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:
After successfully install package, open config/app.php file and add service provider and alias.
config/app.php
Add New Route:
next we need to create route for run get curl request. so open your routes/web.php file and add following route.
routes/web.php
Add Controller Method:
Here, we will add new getCURL() in HomeController so if you don't have HomeController then create and add following method.
app/Http/Controllers/HomeController.php
Now, you can simply run above example and see you will get result 100 data in json, it is very simple as you see, you don't require to anymore use php curl and very easily run curl request.
So you can also run post, put, patch, delete request as bellow example, let's just need to change getCURL() on home page:
CURL Post Request:
CURL Put Request:
CURL Patch Request:
CURL Delete Request:
Read Also: Laravel guzzle http client POST request example
As above requests we can do it very simply. So you can also get more information about curl package from here : ixudra/curl.
I hope you will find your solution.
Last updated