The issue you're encountering seems to be related to the casting of your start and end attributes in the EventsJob model. In Laravel 11, there might be changes in how casting is handled, especially when dealing with queued jobs and serialization.
Here are a few steps you can take to troubleshoot and potentially resolve the issue:
-
Check Casting Method Signature: Ensure that the
castsmethod in your model is correctly defined. In Laravel, thecastsproperty is typically an array, not a method. You should define it as a property like this:class EventsJob extends Model { // ... protected $casts = [ 'start' => 'immutable_date', 'end' => 'immutable_date', 'status' => JobStatus::class, ]; // ... } -
Serialization of Models in Jobs: When a job is serialized, the model's attributes are stored as plain data. Upon deserialization, Laravel should automatically cast these attributes back to their defined types. However, if there's an issue with the casting, it might be due to how the model is being serialized or deserialized.
-
Check for Serialization Issues: Ensure that your
EventsJobmodel is correctly serialized and deserialized. You can add some logging in thehandlemethod to check the types ofstartandendafter the job is deserialized:public function handle(RotaPdfParser $service): void { // Log the types of start and end \Log::info('Start type: ' . gettype($this->eventsJob->start)); \Log::info('End type: ' . gettype($this->eventsJob->end)); $events = (int) $this->eventsJob->start->diffInDays($this->eventsJob->end); // ... } -
Check for Custom Serialization Logic: If you have any custom serialization logic in your model or job, ensure that it correctly handles the casting of attributes.
-
Review Laravel Upgrade Notes: Since you mentioned creating a new app and porting the code, double-check the Laravel 11 upgrade guide to ensure there are no additional changes that might affect model casting or job serialization.
By following these steps, you should be able to identify and resolve the issue with the casting of your start and end attributes in the EventsJob model. If the problem persists, consider creating a minimal reproducible example and testing it in isolation to further diagnose the issue.