Have you tried adding the format in the casting in each model using dates ?
protected $casts = [
'my_date' => 'datetime:Y-m-d',
];
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello guys,
In my resources I am returning date attribute and it gets converted to UTC timezone. I know about changes which took place in Laravel 7 where all dates are converted in ISO format and therefore UTC timezone and that this can be changed by using serializeDate on the model. When I add this method serialization works but only when it is directly returned in response but when I pass the same model to the resource date again gets converted into UTC(ISO format).
From this I am guessing JsonResource has its own serialization logic for dates.
I know I can just do $this->date->timezone(timezone) but I would have to do this in every resource on every date property.
I want to change this logic and maybe make it a Trait and just import it whenever I need it, in whichever resource.
Could this be done and how is my question, any help is appreciated.
Regards, Dusan
Please or to participate in this conversation.