Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 714
KATJ Srinath Avatar asked Nov 08 '18 06:11

KATJ Srinath


2 Answers

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
like image 50
Sapnesh Naik Avatar answered Oct 03 '22 15:10

Sapnesh Naik


Check the latest version of carbon 2 and the latest version of adapter in https://carbon.nesbot.com/#gettingstarted, the instruction to upgrade carbon 1 to 2 is also there.

like image 22
Dendi Handian Avatar answered Oct 03 '22 16:10

Dendi Handian