Install Guzzle in Laravel 5

How to install Guzzle in Laravel 5? I use laravel for my project, but I need a library like a buzz so that I can easily use curl in laravel. Can any body help?

+14
laravel-5 guzzle
source share
6 answers

Open a terminal, go to your laravel project root directory and type

composer require guzzlehttp/guzzle 

Alternatively you can add

 "guzzlehttp/guzzle":"*" 

in your composer.json file you need a section and run the composer update.

+34
source share

Via composer, cd to your laravel project root directory, then

 composer require guzzlehttp/guzzle 

This is true. The buzz is now installed and ready to use.

+8
source share

Add composer.json to requirements

 "guzzlehttp/guzzle": "5.*" 

(5. * is the version of Guzzle, this may be a change, see more in the guzzle github profile)

after editing:

 composer update 

See Guzzle for more details.

+3
source share

Since Guzzle is a universal PHP package that was not specifically created for Laravel , so Laravel users are a little confused because you cannot use the class function statically.

To install and use Guzzle in Laravel 5 (I use it in Laravel 5.7),

 composer require guzzlehttp/guzzle 

Then you should see the guzzlehttp folder in the vendor folder.

To use it, you can

 use GuzzleHttp\Exception\GuzzleException; use GuzzleHttp\Client as GuzzleClient; ... public function testGuzzle() { $client = new GuzzleClient(); ... } 

If you do not want to import the namespace, you can also use it directly, as shown below

 $client = new \GuzzleHttp\Client(); 

As mentioned earlier, you cannot use it β€œstatically”

 GuzzleClient::request('GET', 'https://api.xxxx'); // this will throw you error. 
+1
source share

This can be easily accomplished using the following repo https://github.com/Bogardo/Mailgun

I believe the above link will not have problems with guzzlehttp 5.3 ~ 6.0

However, if you use Oauth with a guzzle version higher than 6.0, compare the files "/composer.json", "/src/Bogardo/Mailgun/Mailgun/MailgunApi.php" between the link above and below. https://github.com/milocosmopolitan/Mailgun

0
source share

Add the file to your composer.json :

 "guzzlehttp/guzzle": "~5.0" 

save and then update the composer.

0
source share

All Articles