How to Use Carbon 2 In Laravel 5.5

I am using Laravel 5.5 and it has Carbon version 1.27 which has no function like

  1. roundHour()
  2. roundMinute()

    which are added in Carbon version 2.

I was trying to update the Carbon version through composer but no success

How can I use Carbon's New version in my Laravel 5.5

2 answers

  • answered 2018-11-08 07:01 Shobi

    open up your composer.json

    goto require -> nesbot/carbon section and change the version to "~2.5.0"

    remove composer.lock file -

    $ rm composer.lock

    just to make sure you are installing fresh packages.

    then do a $ composer install

    you might want to fix any dependency errors as the carbon package requires php7.1 and some existing packages may break it.

    you may want to check out the migration guide for carbon

  • answered 2018-11-08 07:15 Sapnesh Naik

    Carbon update is due in Laravel 5.8 till then the work-around is using laravel-carbon-2 adapter for Laravel.

    Basically, 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