如何使用Laravel 5.6升级Carbon?

时间:2018-07-13 20:10:37

标签: php laravel composer-php php-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.

2 个答案:

答案 0 :(得分:1)

我不建议您谨慎行事,因为Laravel或您的任何其他依赖项可能需要软件包的严格版本。

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

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

请注意,as 1.25.0会欺骗其他软件包,使1.32.0等效于1.25.0。此技巧需要确切的版本。

答案 1 :(得分:1)

Laravel自5.8版开始正式支持Carbon 2,如果要在较低版本上使用它,则可以执行以下步骤:

显式设置Carbon版本并将适配器添加到您的composer.json中:

{
"require": {
    "nesbot/carbon": "2.21.3 as 1.34.0"
 }
}