找不到Laravel类'App \ Http \ Controllers \ GuzzleHttp \ Client'

问题描述:

我已经安装了客户端,并使用 composer dump autoload 进行了更新,但仍然出现相同的错误.通过composer安装后,在项目目录中需要guzzlehttp/guzzle:〜6.0.

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?

您将要熟悉PHP Laravel中的大多数文件都已命名.对命名空间中的函数的调用从该命名空间开始,但有两个例外:

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

如果以\开头类名,则告诉PHP从根级名称空间开始

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

$client = new \GuzzleHttp\Client(); 

或者,您可以输入:

use GuzzleHttp\Client;

位于文件顶部(您会在Laravel的所有默认文件中看到其中的很多个),然后执行

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();