Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PeregrineStudios's avatar

Why don't Model date attributes properly cast when used in a queued job?

I have an Eloquent model, booking. Within that model I define the fields to be automatically cast as Carbon instances:

protected $dates = [
   'start_date', 'end_date'
];

But when I try to access those properties in a queued email job to send a notification about a new booking, they are returned as ordinary strings, not Carbon objects (this is in 5.6).

Is there a reason for this? Am I doing something incorrectly?

0 likes
3 replies
Snapey's avatar

Probably because the model is serialized to be placed on the queue. If the model is likely to still be in the same state, could you re-fetch it?

PeregrineStudios's avatar

Hmm - it was my understanding that by serializing a model that was essentially what you were doing, no? I admit I could definitely be wrong but I thought the 'default behaviour' when using the SerializesModels trait was that it would essentially just store the ID and then retrieve it when the job was handled.

Please or to participate in this conversation.