php Laravel:找不到类“GuzzleHttp\Client”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31227080/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 22:19:11  来源:igfitidea点击:

Laravel: Class 'GuzzleHttp\Client' not found

phplaravelcomposer-phpmandrill

提问by InvalidSyntax

I am trying to use Mandrill to send emails via my Laravel framework, however I am receiving the following error:

我正在尝试使用 Mandrill 通过我的 Laravel 框架发送电子邮件,但是我收到以下错误:

FatalErrorException in MandrillTransport.php line 114: Class 'GuzzleHttp\Client' not found

MandrillTransport.php 第 114 行中的 FatalErrorException:找不到类“GuzzleHttp\Client”

I have installed Guzzle using the following command in Terminal:

我在终端中使用以下命令安装了 Guzzle:

"guzzlehttp/guzzle": "~4.0"

According to Laravel's documentation I need to add "guzzlehttp/guzzle": "~4.0"to my composer.json file, but I'm not sure if where I have placed it is correct as I still see the error.

根据 Laravel 的文档,我需要添加"guzzlehttp/guzzle": "~4.0"到我的 composer.json 文件中,但我不确定我放置它的位置是否正确,因为我仍然看到错误。

{
    "name": "laravel/laravel",
    "description": "The Laravel Framework.",
    "keywords": ["framework", "laravel"],
    "license": "MIT",
    "type": "project",
    "require": {
        "laravel/framework": "5.0.*",
        "illuminate/html": "^5.0",
        "guzzlehttp/guzzle": "~4.0"
    },
    "require-dev": {
        "phpunit/phpunit": "~4.0",
        "phpspec/phpspec": "~2.1"
    },
    "autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\": "app/"
        }
    },
    "autoload-dev": {
        "classmap": [
            "tests/TestCase.php"
        ]
    },
    "scripts": {
        "post-install-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-update-cmd": [
            "php artisan clear-compiled",
            "php artisan optimize"
        ],
        "post-create-project-cmd": [
            "php -r \"copy('.env.example', '.env');\"",
            "php artisan key:generate"
        ]
    },
    "config": {
        "preferred-install": "dist"
    }
}

Here is the list of packages my application has, notice that guzzle has a different version: 4.2.3 which i've also tried updating to but still get the same error. list of packages installed

这是我的应用程序具有的软件包列表,请注意 guzzle 具有不同的版本:4.2.3,我也尝试更新到该版本但仍然遇到相同的错误。 安装的软件包列表

回答by shampoo

Open up your terminal at the root of your project and enter

在项目的根目录打开终端并输入

composer require guzzlehttp/guzzle

It worked for the mailgun API. For some reason, the suggested method at the laravel's mail doc. You may install this package to your project by adding the following line to your composer.jsonfile

它适用于 mailgun API。出于某种原因,laravel 的邮件文档中建议的方法。您可以通过将以下行添加到您的composer.json文件中,将此包安装到您的项目中

"guzzlehttp/guzzle": "~5.3|~6.0"

doesn't make the composer download the Guzzlesource codes. By the way, I didn't find out what |means in determining the version. This command just downloads the PSR code.

不会让作曲家下载Guzzle源代码。顺便说一下,我没有找到|确定版本的含义。此命令仅下载 PSR 代码。

In this moment, the solution may work. However, be aware of compatibility issues. Because the command would install the latest stable version, not the suitable one.

此时,解决方案可能会奏效。但是,请注意兼容性问题。因为该命令会安装最新的稳定版本,而不是合适的.

回答by Grant

If you're using Laravelwhen you run into this error, just run:

如果您在遇到此错误时正在使用Laravel,只需运行:

composer require guzzlehttp/guzzle

And try again.

然后再试一次。

回答by Paul

After updating your composer.jsonfile you need to run the updatecommand to resolve and install your dependencies:

更新composer.json文件后,您需要运行更新命令来解决和安装您的依赖项:

composer update

or, if composer isn't in your path:

或者,如果 composer 不在您的路径中:

php composer.phar update

回答by Ju Chépa

Did you try :

你试过了吗 :

artisan clear-compiled 

or if artisan is not available try to remove compiled.php if exist (in vendor directory) and launch composer dumpautoload

或者如果 artisan 不可用,请尝试删除compiled.php(如果存在)(在供应商目录中)并启动 composer dumpautoload

回答by Muhammad Sulman

simple in my case add "guzzlehttp/guzzle": "^6.3"in composer.jsonrequire object as mentioned below

在我的情况下,添加简单的"guzzlehttp/guzzle": "^6.3"composer.json需要的对象下面所提到

"require": {
        "php": ">=7.0.0",
        "ext-gd": "*",
        "barryvdh/laravel-cors": "^0.11.2",
        "barryvdh/laravel-dompdf": "^0.8.1",
        "dingo/api": "2.0.0-alpha1",
        "doctrine/dbal": "^2.6",
        "fideloper/proxy": "~3.3",
        "guzzlehttp/guzzle": "^6.3",
        "intervention/image": "^2.4",
        "laravel/framework": "5.5.*",
        "laravel/tinker": "~1.0",
        "league/flysystem-aws-s3-v3": "~1.0",
        "predis/predis": "^1.1",
        "tymon/jwt-auth": "dev-develop"
    }, 

than run composer updatein project root using terminal than its working fine.

而不是composer update使用终端在项目根目录中运行而不是它的工作正常。

回答by Larzack

I had the same issue. I used an old version in order to work. It's not working anymore since version 4. It works on version 3.8.1

我遇到过同样的问题。为了工作,我使用了旧版本。从版本 4 开始它不再工作了。它在版本 3.8.1 上工作

So you can add "guzzlehttp/guzzle": "~3" to works

所以你可以添加 "guzzlehttp/guzzle": "~3" 到作品

回答by Goktug Gumus

You can solve this problem to add "mews/captcha": "1.0.1"and "guzzlehttp/guzzle": "~4.0"to your composer.json file. And then you need run composer updatecommand on your terminal.

您可以解决此问题以将"mews/captcha": "1.0.1"和添加"guzzlehttp/guzzle": "~4.0"到您的 composer.json 文件中。然后你需要composer update在终端上运行命令。

I have tried on Laravel 4. It works for me.

我试过 Laravel 4。它对我有用。

回答by boateng

I got this error when I tried running my code outside of the Laravel framework while testing in a stand alone file. It worked for me when I moved it inside a controller.

当我在独立文件中测试时尝试在 Laravel 框架之外运行我的代码时出现此错误。当我将它移到控制器中时,它对我有用。

回答by Gokigooooks

I am oblivious to why this worked for me, I saw this in a forum somewhere

我不知道为什么这对我有用,我在某个论坛上看到了这个

I just added this captcha generator to the composer.json file

我刚刚将这个验证码生成器添加到 composer.json 文件中

"mews/captcha": "~2.0.",

added it to all the require package

将它添加到所有 require 包中

"require": {
    "php": ">=5.5.9",
    "laravel/framework": "5.1.*",
    "laravelcollective/html": "5.1.*",
    "laracasts/flash": "~1.3",
     "mews/captcha": "~2.0.",
    "guzzlehttp/guzzle": "~4.0"
    },

If someone knows why this worked it would really scratch the itch in my brain.

如果有人知道这为什么会奏效,那真的会让我脑子里痒痒的。