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

kha333n's avatar

Updated Laravel from 10 to 11 Carbon Issue

I have upgraded Laravel from 10 to 11 by setting PHP 8.2 and updating the composer file.

Now I have issue with carbon.

"message": "Carbon\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given, called in /home/kha333n/repo/rms360/vendor/nesbot/carbon/src/Carbon/Traits/Units.php on line 356",
    "exception": "TypeError",

Traces point to this line in my project.

eturn response()->json([
            'status' => 'success',
            'message' => __('auth.login'),
            'data' => [
                'user' => $loginRequest->user(),
                'token' => $loginRequest->user()->createToken('authToken', ['*'], now()->addMinutes(config('session.lifetime')))->plainTextToken
            ]
        ]);

Token line in this.

here is my composer file

{
    "name": "laravel/laravel",
    "type": "project",
    "description": "The Laravel Framework.",
    "keywords": [
        "framework",
        "laravel"
    ],
    "license": "MIT",
    "require": {
        "php": "^8.2",
        "dompdf/dompdf": "^v2.0",
        "guzzlehttp/guzzle": "^7.8.0",
        "laravel/cashier": "^15.0",
        "laravel/framework": "^11.0",
        "laravel/sanctum": "^4.0",
        "laravel/socialite": "^v5.13.0",
        "laravel/tinker": "^v2.9.0",
        "predis/predis": "^2.2",
        "sentry/sentry-laravel": "^4.5",
        "spatie/laravel-medialibrary": "^11.0",
        "spatie/laravel-permission": "^6.7.0",
        "spatie/laravel-tags": "^4.6.1",
        "spatie/period": "^2.4",
        "spomky-labs/otphp": "^11.2",
        "stancl/tenancy": "^v3.8.2",
        "touhidurabir/laravel-stub-generator": "^1.0.8"
    },
    "require-dev": {
        "ext-pdo": "*",
        "fakerphp/faker": "^v1.23.1",
        "laravel/breeze": "^2.0",
        "laravel/pint": "^v1.15.1",
        "laravel/sail": "^v1.29.1",
        "mockery/mockery": "^1.6.11",
        "nunomaduro/collision": "^8.1",
        "phpunit/phpunit": "^11.1.2",
        "spatie/laravel-ignition": "^2.5.2"
    },
    "autoload": {
        "psr-4": {
            "App\": "app/",
            "Database\Factories\": "database/factories/",
            "Database\Seeders\": "database/seeders/"
        }
    },
    "autoload-dev": {
        "psr-4": {
            "Tests\": "tests/"
        }
    },
    "scripts": {
        "post-autoload-dump": [
            "Illuminate\Foundation\ComposerScripts::postAutoloadDump",
            "@php artisan package:discover --ansi",
            "@php artisan vendor:publish --force --tag=livewire:assets --ansi"
        ],
        "post-update-cmd": [
            "@php artisan vendor:publish --tag=laravel-assets --ansi --force"
        ],
        "post-root-package-install": [
            "@php -r \"file_exists('.env') || copy('.env.example', '.env');\""
        ],
        "post-create-project-cmd": [
            "@php artisan key:generate --ansi"
        ]
    },
    "extra": {
        "laravel": {
            "dont-discover": []
        }
    },
    "config": {
        "optimize-autoloader": true,
        "preferred-install": "dist",
        "sort-packages": true,
        "allow-plugins": {
            "pestphp/pest-plugin": true,
            "php-http/discovery": true
        }
    },
    "minimum-stability": "dev",
    "prefer-stable": true
}

did I missed something or some package need to remove, add in Laravel 11?

0 likes
6 replies
tykus's avatar

What is the actual value of your session.lifetime?

kha333n's avatar
kha333n
OP
Best Answer
Level 1

@tykus 120

but it reads it as string "120" and it requires exact float|int

I fixed that but problem are everywhere so I just reverted back to laravel 10. 😎

tykus's avatar

@kha333n or, you could cast as an int either where it is used

(int) config('session.lifetime'))

or in the config

'lifetime' => (int) env('SESSION_LIFETIME', 120),

Since .env values all are strings, your config is being set as a string rather than an int, so you must take steps to change the type.

1 like
technofreaks's avatar

Laravel 11 upgrade Guide

laravel.com/docs/11.x/upgrade#floating-point-types
laravel.com/docs/11.x/upgrade#carbon-3
shalomews's avatar

Basically you cannot pass strings into the "addDays" or any "addSomething" in Carbon.

What is the Carbon version in the composer.lock file? When I went from Laravel 10 to 11 it automatically rasied my Carbon version for some reason even thought it was not in the composer.json

shalomews's avatar

see the issue on github here briannesbitt/Carbon/issues/3028

Please or to participate in this conversation.