Cannot upgrade Carbon 1 to Carbon 2
Asked Answered
F

2

8

I've been working on a Laravel project. When I run composer command, I always got warned,

Carbon 1 is deprecated, see how to migrate to Carbon 2. https://carbon.nesbot.com/docs/#api-carbon-2 You can run './vendor/bin/upgrade-carbon' to get help in updating carbon and other frameworks and libraries that depend on it.

Then I run the ./vendor/bin/upgrade-carbon but I got error,

Uncaught Error: Class 'Composer\Composer' not found in .../vendor/nesbot/carbon/src/Carbon/Upgrade.php:131

I have also try to search for solutions but it cant be found. I really need help to continue my project. Thanks a lot.

Frendel answered 8/8, 2019 at 8:47 Comment(0)
M
9

add the following dependencies to your composer.json**:

{
  ...
  "require": {
    ...
    "kylekatarnls/laravel-carbon-2": "^1.0.0",
    "nesbot/carbon": "2.0.0-beta.2 as 1.25.0"
  }
  ...
}

then run:

composer update
Mennonite answered 8/8, 2019 at 9:9 Comment(2)
This is reflecting this > Illuminate\Foundation\ComposerScripts::postAutoloadDump PHP Fatal error: Cannot declare class Illuminate\Support\Carbon, because the name is already in use in /opt/lampp/htdocs/project_name/vendor/kylekatarnls/laravel-carbon-2/src/Carbon.php on line 9 what should i do ?Brucine
"nesbot/carbon": "2.0.0 as 1.25.0" is enoughDelphiadelphic
G
3

It seems composer is not up to date. Try first to run composer self-update then retry ./vendor/bin/upgrade-carbon

In any case, it's a deprecation notice, it doesn't mean you can't continue your project. It just tells you this particular package will no longer receive any update and as for as Carbon is concerned, you will lack many features you would found in the current documentation.

You say your on a Laravel project, so you didn't install carbon yourself probably. Then the first thing to consider is to upgrade to Laravel 5.8 (which use Carbon 2 by default) and is the only version Laravel still supports.

Gruff answered 13/8, 2019 at 5:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.