Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rnooxx999 opened this issue Apr 29, 2024 · 3 comments · May be fixed by #2257

Comments

@rnooxx999
Copy link

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
Copy link

@rnooxx999 Here is the temporary solution: Link

@D-Redouane
Copy link

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.

D-Redouane added a commit to D-Redouane/jwt-auth that referenced this issue Apr 29, 2024
…ent variable

The env file is passing values as string and if manually the developer set the JWT_TTL value in the env file an error of : 
```
Carbon\\Carbon::rawAddUnit(): Argument tymondesigns#3 ($value) must be of type int|float, string given,
```
will appear

Fixes tymondesigns#2256
@rnooxx999
Copy link
Author

JWT_TTL=4320

Thank you it's Work ..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants