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

六眼飞鱼酱① 提交于 2020-01-01 15:23:44

问题


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?


回答1:


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



回答2:


You might have not installed guzzle.

Run composer require guzzlehttp/guzzle to install it



来源:https://stackoverflow.com/questions/46870356/laravel-class-app-http-controllers-guzzlehttp-client-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!