1

I am facing an issue in a laravel project. It's showing this error

Fatal Error : Class 'Guzzle\Http\Client' not found

I have Guzzle installed and added to configuration file. Also I have added the use GuzzleHttp\Client; in my Controller but still its showing the error.

This is the code am using:

$client = new GuzzleHttp\Client();

Anyone please help. Thanks

7
  • are you certain you have guzzle in your project? what laravel version are you using? Commented Oct 16, 2019 at 5:28
  • laravel version is 5.5 Commented Oct 16, 2019 at 5:30
  • go to the root of your project, and run composer require guzzlehttp/guzzle Commented Oct 16, 2019 at 5:30
  • Its already installed "guzzlehttp/guzzle": "~6.0", Commented Oct 16, 2019 at 5:32
  • declare guzzle at the top of your controller as such; use GuzzleHttp\Client; and to call it in your function use this; $client = new Client(); Commented Oct 16, 2019 at 5:34

2 Answers 2

3

You have missed a '\'. Add it and will resolve the issue.

$client = new \GuzzleHttp\Client();

If you will add it on the top of your controller like

use GuzzleHttp\Client as GuzzleHttp;

then you can access it just by

$client = new GuzzleHttp();

I have used as because there may be Client already in use.

If you have added class into aliases in config/app.php like

'GuzzleHttp' => \GuzzleHttp\Client::class

then just use it like this in controller

use GuzzleHttp;
Sign up to request clarification or add additional context in comments.

Comments

1

Just a minor mistake. Please add the '\' with GuzzleHttp\Client(); like given below:

$client = new \GuzzleHttp\Client();

For reference, you can check the documentation here

https://github.com/guzzle/guzzle

Send an asynchronous request.

You can send an asynchronous request like this:

$request = new \GuzzleHttp\Psr7\Request('GET', 'http://httpbin.org');

If it doesn't work, please try to update the Guzzle as per your laravel version:

You can then update Guzzle using composer:

composer update

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.