How to Use Carbon 2 In Laravel 5.5

KATJ Srinath picture KATJ Srinath · Nov 8, 2018 · Viewed 8.4k times · Source

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

Answer

Sapnesh Naik picture Sapnesh Naik · Nov 8, 2018

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