使用 composer 安装 Laravel 包的问题

Posted

技术标签:

【中文标题】使用 composer 安装 Laravel 包的问题【英文标题】:Problem with installing a Laravel package using composer 【发布时间】:2021-03-11 13:21:43 【问题描述】:

我想在我的项目中使用一个包。

作曲家.json:

"require": 
    "php": "^7.2.5|^8.0",
    "fideloper/proxy": "^4.4",
    "fruitcake/laravel-cors": "^2.0",
    "guzzlehttp/guzzle": "^6.3.1|^7.0.1",
    "hekmatinasser/verta": "^1.11",
    "laravel/framework": "^7.29",
    "laravel/passport": "^9.3",
    "laravel/tinker": "^2.5",
    "lcobucci/jwt": "3.3.3",
    "pishran/zarinpal": "^2.2"
,

我要安装的目标包:

composer require ipecompany/smsirlaravel

问题:当我在 composer 上尝试这个时,我看到以下错误

Problem 1
- ipecompany/smsirlaravel[v1.0.0, ..., v1.0.7] require guzzlehttp/guzzle ~6.0 -> found guzzlehttp/guzzle[6.0.0, ..., 6.5.x-dev] but the package is fixed to 7.2
.0 (lock file version) by a partial update and that version does not match. Make sure you list it as an argument for the update command.
- Root composer.json requires ipecompany/smsirlaravel ^1.0 -> satisfiable by ipecompany/smsirlaravel[v1.0.0, ..., v1.0.7].

我试过了:

composer require ipecompany/smsirlaravel -W

但主要问题是Laravel Passport 可能是因为以下错误:

  Problem 1
    - laravel/passport is locked to version v9.3.2 and an update of this package was not requested.
    - laravel/passport v9.3.2 requires laminas/laminas-diactoros ^2.2 -> found laminas/laminas-diactoros[2.2.0, ..., 2.6.x-dev] but it conflicts with another require.

我尝试安装laminas/laminas-diactoros ^2.2,但又遇到一个错误

problem 1
    - Root composer.json requires laminas/laminas-diactoros 2.2, found laminas/laminas-diactoros[2.2.0] but it conflicts with another require.
  Problem 2
    - laravel/passport is locked to version v9.3.2 and an update of this package was not requested.
    - laravel/passport v9.3.2 requires laminas/laminas-diactoros ^2.2 -> found laminas/laminas-diactoros[2.2.0, ..., 2.6.x-dev] but it conflicts with another require.

任何机构可以帮助我安装这个包? TNX

【问题讨论】:

【参考方案1】:

如第一条错误消息中所述:ipecompany/smsirlaravel 需要 v6 的 Guzzle,但当前已安装 v7。您应该首先对 Guzzle 使用不同的版本约束:将 "guzzlehttp/guzzle": "^6.3.1|^7.0.1" 更改为 "guzzlehttp/guzzle": "^6.3.1"。然后,运行 composer update guzzlehttp/guzzle 以安装 Guzzle v6。

之后,运行 composer require ipecompany/smsirlaravel 应该可以工作

【讨论】:

以上是关于使用 composer 安装 Laravel 包的问题的主要内容,如果未能解决你的问题,请参考以下文章

laravel巧用composer

如何使用 PHP Composer 从 Laravel 中删除一个包?

没有composer可以安装或者正常使用laravel么

composer安装laravel-u-editor及其使用

Laravel 5.2 - 使用 composer 和 git bash 安装 laravel 时出错

全局安装 Composer 以供 laravel 使用?