找不到Laravel类'App \ Http \ Controllers \ GuzzleHttp \ Client' [英] Laravel Class 'App\Http\Controllers\GuzzleHttp\Client' not found

查看:378
本文介绍了找不到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();

这篇关于找不到Laravel类'App \ Http \ Controllers \ GuzzleHttp \ Client'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆