如何使用 Laravel 5.6 升级 Carbon?

Sár*_*ály 5 php laravel composer-php php-carbon

我在 cmd 中试过“composer 需要 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.
Run Code Online (Sandbox Code Playgroud)

Dev*_*von 4

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

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

"require": {
    ...
    "nesbot/carbon": "1.32.0 as 1.25.0"
},
Run Code Online (Sandbox Code Playgroud)

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

  • 也许你可以将类添加到你的项目中,比如`app\Util\CarbonPeriod.php` https://github.com/briannesbitt/Carbon/blob/master/src/Carbon/CarbonPeriod.php (2认同)