Laravel Class 'App\Http\Controllers\GuzzleHttp\Client' not found

Ted Heath picture Ted Heath · Oct 22, 2017 · Viewed 15.5k times · Source

I've installed the client and I did an update using composer dump autoload but I still end up with the same error. After installing via composer require guzzlehttp/guzzle:~6.0 in the projects directory.

 $client = new GuzzleHttp\Client(); 

Why isn' it working and why is it even referencing the wrong directory?

Answer

ceejayoz picture ceejayoz · Oct 22, 2017

You're going to want to get acquainted with PHP namespaces.

Most files in Laravel are namespaced. Calls to functions within a namespace start within that namespace, with two exceptions:

If you start the class name with a \, that tells PHP to start at the root-level namespace:

$client = new \GuzzleHttp\Client(); 

Or, you can put:

use GuzzleHttp\Client;

at the top of the file (you'll see a lot of these already throughout Laravel's default files) and then do

$client = new Client();