How can I upgrade Carbon with Laravel 5.6?
Asked Answered
K

2

5

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

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.
Karikaria answered 13/7, 2018 at 20:10 Comment(2)
Do you need a new feature or something? It looks like Laravel 5.6 has only allowed version 1.25 so you'd be potentially breaking that dependency by upgrading to something newer.Impediment
Unless you want a new feature of Carbon there is no need to upgrade it. The error says itself, it's a requirement for Laravel to maintain that versionfor the 5.6 versionRemittance
I
4

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.

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

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

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

Impediment answered 13/7, 2018 at 20:32 Comment(3)
My reason is to use CarbonPeriod, which is not available in this version.Receptionist
And doesn't allow me to upgrade with your suggestion either.Receptionist
And maybe you can just add the class to your Project say in app\Util\CarbonPeriod.php github.com/briannesbitt/Carbon/blob/master/src/Carbon/…Coelho
T
2

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:

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

{
"require": {
    "nesbot/carbon": "2.21.3 as 1.34.0"
 }
}
Tuyere answered 29/7, 2019 at 11:56 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.