Fix type casting for Carbon 3 compatibility in RedisJobRepository #1580
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Carbon 3 Compatibility Fix for RedisJobRepository
Laravel Horizon uses Carbon's addMinutes() and subMinutes() methods throughout the RedisJobRepository class for job expiration and cleanup operations. These methods are called with configuration values retrieved via Laravel's config() helper.
The Problem:
Carbon 3 introduced stricter type checking and no longer accepts string values for time manipulation methods like addMinutes() and subMinutes(). The config() helper can return string values (especially when reading from environment variables), which causes type errors in Carbon 3.
The Solution:
This patch adds explicit integer casting (int) to all configuration values in the RedisJobRepository constructor:
Testing Examples:
Without this fix, the following common Laravel job operations would fail with Carbon 3:
Error Example (before fix):
TypeError: Carbon\CarbonImmutable::addMinutes(): Argument #1 ($value) must be of type int, string given
Without the integer casting, Carbon 3 will throw type errors when these configuration values are strings, breaking job expiration, cleanup, and monitoring
functionality in Laravel Horizon.
This change maintains backward compatibility while ensuring Laravel Horizon works correctly with both Carbon 2 and Carbon 3, supporting Laravel 11's requirements.