tymondesigns / jwt-auth

🔐 JSON Web Token Authentication for Laravel & Lumen
https://jwt-auth.com
MIT License
11.23k stars 1.55k forks source link

TypeError: Carbon\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given, #2256

Open rnooxx999 opened 2 months ago

rnooxx999 commented 2 months ago

after updating Laravel to version 11 this problem showing up

TypeError: Carbon\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given, called in Documents/Sites/../vendor/nesbot/carbon/src/Carbon/Traits/Units.php on line 356 in file /Documents/Sites/../vendor/nesbot/carbon/src/Carbon/Traits/Units.php on line 455

ks-dipeshc commented 2 months ago

@rnooxx999 Here is the temporary solution: Link

D-Redouane commented 2 months ago

If you're dealing with the following error message:

Carbon\\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given

it's likely because the JWT 'ttl' (time to live) value was passed as a string instead of an integer. I found that this could be fixed by casting the 'ttl' to an integer in the JWT configuration file. Here's what I did to resolve the issue:

// Inside config/jwt.php
'ttl' => (int) env('JWT_TTL', 60),  // Cast to int to avoid errors

If you need to change the 'ttl' to a different value, like 4320, be cautious about how you set it in your .env file. If you simply write JWT_TTL=4320, there's a risk it might still be interpreted as a string. Instead, it's safer to update the configuration directly:

// Inside config/jwt.php
'ttl' => (int) env('JWT_TTL', 4320),  // Ensures 'ttl' is always cast to int

This way, regardless of how the 'ttl' value is specified in the environment file, you can be sure that it will be correctly interpreted as an integer, preventing the type mismatch error.

Hopefully, this helps you avoid similar issues.

rnooxx999 commented 2 months ago

JWT_TTL=4320

Thank you it's Work ..