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

se's avatar
Level 1

Mutator causes date attributes to be JSON object instead of a serialized date string

I'd like to use Cake\Chronos\Date for my date attributes. Since attribute casting via $casts will give me Carbon\Carbon and there doesn't seem to be a way to change that, I just wrote a mutator for my date attributes. This works as expected, but there's one problem.

In Illuminate\Database\Eloquent\Concerns\HasAttributes the method addCastAttributesToArray() won't reach serializeDate() for mutated attributes, so my JSON response changes from serialized date strings to JSON objects.

Is there anything I can do to prevent this?

0 likes
0 replies

Please or to participate in this conversation.