如何使用 Laravel 5.6 升级 Carbon?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/51332201/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 17:54:14  来源:igfitidea点击:

How can I upgrade Carbon with Laravel 5.6?

phplaravelcomposer-phpphp-carbon

提问by Sára Kata Király

I tried in cmd "composer require nesbot/carbon" but I got this:

我在 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.

回答by Devon

I don't recommend doing this without extreme caution because there may be a reason why Laravel, or any of your other dependencies, require a very strict version of a package.

我不建议在没有非常谨慎的情况下执行此操作,因为 Laravel 或任何其他依赖项需要非常严格的包版本可能是有原因的。

With that said, Composer does include a neat trick to alias versions to get around this by specifying an alias version in composer.json:

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

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

Note the as 1.25.0which will trick other packages into thinking 1.32.0is equivalent to 1.25.0for dependencies. This trick requires exact versions.

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

回答by Manoj Patel

Carbon 2 is officially supported by Laravel since the version 5.8, if you want to use it on a lower version, you can follow those steps:

从 5.8 版本开始,Laravel 正式支持 Carbon 2,如果您想在较低版本上使用它,您可以按照以下步骤操作:

Set explicitly the Carbon version and add the adapter in your composer.json:

明确设置 Carbon 版本并在 composer.json 中添加适配器:

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