本地的一个 Laravel5.5 的项目有段时间没有更新包了,今天执行了一下 composer update 想更新一下扩展包,发现报了一个错,内容如下:

Updating dependencies (including require-dev)
Package operations: 1 install, 1 update, 0 removals
  - Installing kylekatarnls/update-helper (1.1.0): Loading from cache
  - Downgrading nesbot/carbon (2.16.3 => 1.38.2): Loading from cache
Package phpunit/phpunit-mock-objects is abandoned, you should avoid using it. No replacement was suggested.
Writing lock file
Generating optimized autoload files
*******************************************
 /!\ Warning, you're using a deprecated
 ¨¨¨ version of Carbon, we will soon stop
p
     providing support and update for 1.x
     versions, please upgrade to Carbon 2.
*******************************************
Most features of Carbon 1 are still available in Carbon 2.
See how to migrate: https://carbon.nesbot.com/docs/#api-carbon-2
Please consider upgrading your Laravel dependencies to be compatible with Carbon 2:
  - laravel/framework at least to version 5.8.0
If you can't update Laravel, check https://carbon.nesbot.com/ to see how to
install Carbon 2 using alias version and our adapter kylekatarnls/laravel-carbon-2
You can run ".\vendor\bin\upgrade-carbon" to get help in updating carbon and other frameworks and libraries that depend on it.

这个报错的大概意思是:nesbot/carbon 这个扩展包将要被废弃,建议我们升级到 carbon-2,但是carbon-2 要求 Laravel 的最低版本是5.8。但是我用的是Laravel5.5,而且是线上项目,不能随便升级,对于这种情况,官方也给出了方案,解决方案如下。

在 composer.json 文件 require 部分,添加以下两行:

"kylekatarnls/laravel-carbon-2": "^1.0.0",
"nesbot/carbon": "2.16.3 as 1.34.0"

修改完之后,再次执行composer update就可以了。

本文为 陈华 原创,欢迎转载,但请注明出处:http://www.ichenhua.cn/blog/post/43