How can I autoload Guzzle in Laravel 4?
I am encountering the following error when I try to create a new GuzzleHttp/Client:
Symfony \ Component \ Debug \ Exception \ FatalErrorException
Class 'GuzzleHttp\Client' not found
I have the following set up in my composer.json autoload section:
autoload: {
"psr-0": {
"Guzzle\\": "src/"
}
}
You don't need to add Guzzle to your composer.json, it's already autoloaded by it's own composer.json.
composer require "guzzlehttp/guzzle" "~4.0"
Create a client:
$client = new \GuzzleHttp\Client();
Get results:
$response = $client->get('http://api.github.com/users/antonioribeiro');
dd($response->getBody());
Install it:
composer require "guzzle/guzzle" "~3.0"
Create a client setting the base URL:
$client = new \Guzzle\Service\Client('http://api.github.com/users/');
Get your response:
$username = 'antonioribeiro';
$response = $client->get("users/$username")->send();
And display it:
dd($response);
If you still don't get it running, check the file vendor/composer/autoload_psr4.php
, Guzzle must appear in it. If it doesn't, remove your vendor folder and install it again:
rm -rf vendor
rm composer.lock
composer install
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With