未找到 Laravel 类“AppHttpControllersGuzzleHttpClient"未找到、Laravel、quot、AppHttpControllersGuzzleHttpC

2023-09-06 16:49:47 作者:仙巴佬

我已经安装了客户端并使用 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 GuzzleHttpClient(); 

为什么它不起作用,为什么它甚至引用了错误的目录?

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

推荐答案

你会想要熟悉 PHP 命名空间.

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

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

或者,你可以说:

use GuzzleHttpClient;

在文件的顶部(你会在 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();
 
精彩推荐