Search code examples
phplaravellaravel-5.5php-carbon

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


Solution

  • 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