【问题标题】:Installation Guzzle in Laravel 5Laravel 5 中的安装问题
【发布时间】:2015-10-22 20:21:18
【问题描述】:

如何在 Laravel 5 中安装 Guzzle? 我在我的项目中使用 laravel,但我需要像 guzzle 这样的库来让我在 laravel 中轻松使用 curl。任何机构都可以提供帮助?

【问题讨论】:

    标签: laravel-5 guzzle


    【解决方案1】:

    打开一个终端,进入你的 laravel 项目根目录并输入

    composer require guzzlehttp/guzzle
    

    或者,您可以添加

    "guzzlehttp/guzzle":"*"
    

    到您的 composer.json 文件的 require 部分并运行 composer update。

    【讨论】:

    • 如何实现 guzzle 作为库或助手?
    • 实现,并调用控制器
    • @baao 这应该更新为composer require guzzlehttp/guzzle - 因为composer require guzzle/guzzle 已被放弃 - 请参阅packagist.org/packages/guzzle/guzzle
    • 我在敲我的头......我找不到类'Symfony\Bridge\PsrHttpMessage\Factory\HttpFoundationFactory'
    【解决方案2】:

    这可以通过使用以下 repo 轻松完成 https://github.com/Bogardo/Mailgun

    我相信上面的链接对于guzzlehttp 5.3 ~ 6.0不会有问题

    但是,如果您使用 6.0 以上的 guzzle 版本的 Oauth, 比较以上链接和以下链接之间的“/composer.json”、“/src/Bogardo/Mailgun/Mailgun/MailgunApi.php”文件。 https://github.com/milocosmopolitan/Mailgun

    【讨论】:

      【解决方案3】:

      通过composer,cd进入你的laravel项目根目录,然后

      composer require guzzlehttp/guzzle
      

      就是这样。现在 guzzle 已安装并可以使用了。

      【讨论】:

        【解决方案4】:

        在 require 中添加到您的 composer.json 文件:

        "guzzlehttp/guzzle": "~5.0"
        

        保存然后更新您的作曲家。

        【讨论】:

          【解决方案5】:

          添加到 composer.json 要求中

          "guzzlehttp/guzzle": "5.*"
          

          (5.* 是 Guzzle 版本,可以在 guzzle github 配置文件中查看更多内容)

          编辑运行后:

          composer update
          

          欲了解更多信息,请参阅Guzzle

          【讨论】:

            【解决方案6】:

            由于 Guzzle 是一个通用的 PHP 包,并不是专门为 Laravel 构建的,因此 Laravel 用户有点困惑,因为你不能“静态地”使用类函数.

            要在 Laravel 5 中安装和使用 Guzzle(我在 Laravel 5.7 中使用),

            composer require guzzlehttp/guzzle
            

            然后您应该会在 vendor 文件夹中看到 guzzlehttp 文件夹。

            要使用它,你可以

            use GuzzleHttp\Exception\GuzzleException;
            use GuzzleHttp\Client as GuzzleClient;
            ...
            public function testGuzzle()
            {
                $client = new GuzzleClient();
                ...
            }
            

            如果不想导入命名空间,也可以直接使用如下

            $client = new \GuzzleHttp\Client();
            

            如前所述,您不能“静态地”使用它

            GuzzleClient::request('GET', 'https://api.xxxx'); // this will throw you error.
            

            【讨论】:

              猜你喜欢
              • 2016-07-01
              • 2013-12-13
              • 2013-05-30
              • 2016-11-02
              • 2020-10-25
              • 2019-02-11
              • 1970-01-01
              • 1970-01-01
              • 2021-04-03
              相关资源
              最近更新 更多