You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using the tokenById function, the error Carbon\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given, called in /var/www/html/vendor /nesbot/carbon/src/Carbon/Traits/Units.php on line 356 is fired.
The problem occurred with the variable JWT_TTL which is arriving as a string instead of an integer when this function is called
/**
* Get the Expiration (exp) claim.
*
* @return int
*/
public function exp()
{
return Utils::now()->addMinutes($this->ttl)->getTimestamp();
}
This change resolved the issue in an alternative way:
$ttl = (int) $this->ttl;
return Utils::now()->addMinutes($ttl)->getTimestamp();
Your environment
Q
A
Bug?
yes
New Feature?
no
Framework
Laravel
Framework version
11.2.0
Package version
2.1.1
PHP version
8.2.16
Steps to reproduce
Perform a simple authentication using the auth()->tokenById($id) function.
The text was updated successfully, but these errors were encountered:
I encountered a similar issue with the Carbon\Carbon::rawAddUnit() error due to the JWT ttl value being passed as a string. I managed to resolve this by ensuring that the ttl value is cast to an integer directly in the configuration file. This might help anyone else experiencing this error.
Here’s how I modified the configuration:
// In config/jwt.php'ttl' => (int) env('JWT_TTL', 60), // Cast to int here
This change ensures that the ttl value is always an integer, regardless of how it's specified in the environment variables. It might be helpful to include this type of casting within the library itself to prevent similar issues.
Subject of the issue
When using the tokenById function, the error Carbon\Carbon::rawAddUnit(): Argument #3 ($value) must be of type int|float, string given, called in /var/www/html/vendor /nesbot/carbon/src/Carbon/Traits/Units.php on line 356 is fired.
The problem occurred with the variable JWT_TTL which is arriving as a string instead of an integer when this function is called
/**
* Get the Expiration (exp) claim.
*
* @return int
*/
public function exp()
{
return Utils::now()->addMinutes($this->ttl)->getTimestamp();
}
This change resolved the issue in an alternative way:
$ttl = (int) $this->ttl;
return Utils::now()->addMinutes($ttl)->getTimestamp();
Your environment
Steps to reproduce
Perform a simple authentication using the auth()->tokenById($id) function.
The text was updated successfully, but these errors were encountered: