Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 241
Ted Heath Avatar asked Oct 22 '17 03:10

Ted Heath


People also ask

How to use guzzle HTTP client requests in Laravel?

Follow the below steps and use guzzle HTTP client requests in laravel apps: First of all, Open your terminal and run the following command to download or install laravel fresh new setup: After that, open “.env” file and update the database name, username, and password in the env file:

How to install Laravel on Linux?

First of all, Open your terminal and run the following command to download or install laravel fresh new setup: After that, open “.env” file and update the database name, username, and password in the env file:

Why do I need to import storage class in Laravel?

You need to import Storage class because it’s a facade. Add. For example: Class ‘App\Http\Controllers\Storage’ not found <?php namespace App\Http\Controllers; use Storage; class UserController { ...

How to create postcontroller and guzzlecontroller in WordPress?

After you have to put bellow code in your Post model file for create posts table. Next step, Navigate to “routes/web.php” file and add the following routes into your web.php file: This command will create PostController and GuzzleController by the artisan command.


2 Answers

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();
like image 91
ceejayoz Avatar answered Oct 19 '22 12:10

ceejayoz


You might have not installed guzzle.

Run composer require guzzlehttp/guzzle to install it

like image 22
Constant Avatar answered Oct 19 '22 14:10

Constant