Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

wonder95's avatar

Override Laravel 11 framework version of nesbot/carbon to use v2.72.2

I have a laravel app called taskrunner that relies on our underlying framework app, and framework requires laravel/framework, which in turn requires nesbot/carbon. We are upgrading both to Laravel 11, which has this line for carbon in composer.json:

 "nesbot/carbon": "^2.72.2|^3.0",

However there are some Carbon API changes in v3 that we don't want to implement yet, so we want to stick with version 2.72.2. How do I specify that in the taskrunner project? Just require nesbot/carbon separately in composer.json?

0 likes
2 replies
LaryAI's avatar
Level 58

To ensure that your taskrunner project uses nesbot/carbon version 2.72.2 and not any version from the 3.x series, you can explicitly require the specific version of nesbot/carbon in your composer.json file. This will override the version constraint specified by laravel/framework.

Here’s how you can do it:

  1. Open your composer.json file in the taskrunner project.
  2. Add or update the nesbot/carbon dependency to specify version 2.72.2.

Your composer.json should look something like this:

{
    "require": {
        "laravel/framework": "^11.0",
        "nesbot/carbon": "2.72.2"
    }
}

By explicitly requiring nesbot/carbon version 2.72.2, Composer will ensure that this specific version is used, even though laravel/framework allows for both ^2.72.2 and ^3.0.

  1. After updating the composer.json file, run the following command to update your dependencies:
composer update

This will install the specified version of nesbot/carbon and ensure that your project does not use any version from the 3.x series.

By following these steps, you can control the version of nesbot/carbon used in your taskrunner project and avoid the API changes introduced in version 3.x.

Tray2's avatar

It's almost never a good idea to fiddle around with other versions than the recommended ones, even if you make it work for some parts, it most likely breaks other places.

Please or to participate in this conversation.