首页 > 解决方案 > 如何使用 Laravel 5.6 升级 Carbon?

问题描述

我在 cmd "composer require nesbot/carbon" 中试过,但我得到了这个:

Your requirements could not be resolved to an installable set of packages.

  Problem 1

    - laravel/framework v5.6.27 requires nesbot/carbon 1.25.* -> satisfiable by nesbot/carbon[1.25.0] but these conflict with your requirements or minimum-stability.
    - laravel/framework v5.6.27 requires nesbot/carbon 1.25.* -> satisfiable by nesbot/carbon[1.25.0] but these conflict with your requirements or minimum-stability.
    - laravel/framework v5.6.27 requires nesbot/carbon 1.25.* -> satisfiable by nesbot/carbon[1.25.0] but these conflict with your requirements or minimum-stability.
    - Installation request for laravel/framework (locked at v5.6.27, required as 5.6.*) -> satisfiable by laravel/framework[v5.6.27].


Installation failed, reverting ./composer.json to its original content.

标签: phplaravelcomposer-phpphp-carbon

解决方案


我不建议在没有特别谨慎的情况下这样做,因为 Laravel 或您的任何其他依赖项可能需要非常严格的包版本。

话虽如此,Composer 确实包含了一个巧妙的别名版本技巧,可以通过在以下位置指定别名版本来解决此问题composer.json

"require": {
    ...
    "nesbot/carbon": "1.32.0 as 1.25.0"
},

请注意as 1.25.0which 会欺骗其他包认为1.32.0等同1.25.0于依赖项。这个技巧需要精确的版本。


推荐阅读