找不到 Laravel 类“App\Http\Controllers\GuzzleHttp\Client”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46870356/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Laravel Class 'App\Http\Controllers\GuzzleHttp\Client' not found
提问by Ted Heath
I've installed the client and I did an update using composer dump autoloadbut I still end up with the same error. After installing via composer require guzzlehttp/guzzle:~6.0 in the projects directory.
我已经安装了客户端并使用composer dump autoload进行了更新,但最终还是出现了同样的错误。通过 composer 安装后,在项目目录中需要 guzzlehttp/guzzle:~6.0。
$client = new GuzzleHttp\Client();
Why isn' it working and why is it even referencing the wrong directory?
为什么它不起作用,为什么它甚至引用了错误的目录?
回答by ceejayoz
You're going to want to get acquainted with PHP namespaces.
您会想要熟悉 PHP名称空间。
Most files in Laravel are namespaced. Calls to functions within a namespace start within that namespace, with two exceptions:
Laravel 中的大多数文件都是命名空间的。对命名空间内的函数的调用在该命名空间内开始,但有两个例外:
If you start the class name with a \
, that tells PHP to start at the root-level namespace:
如果类名\
以 开头,则告诉 PHP 从根级命名空间开始:
$client = new \GuzzleHttp\Client();
Or, you can put:
或者,您可以输入:
use GuzzleHttp\Client;
at the top of the file (you'll see a lotof these already throughout Laravel's default files) and then do
在文件的顶部(你会在 Laravel 的默认文件中看到很多这些),然后做
$client = new Client();
回答by Titox d boss
You might have not installed guzzle.
您可能没有安装 guzzle。
Run composer require guzzlehttp/guzzle
to install it
运行composer require guzzlehttp/guzzle
安装