This only works if you use the correct Carbon namespace
use Illuminate\Support\Carbon;
Also note that this only happens for content that is being parsed to JSON. Not for arrays and other kind of objects.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello,
I want to have all dates returned from my requests to have a specific format. I followed the documentation at https://laravel.com/docs/5.8/eloquent-serialization#date-serialization
So, in my AppServiceProvider inside the method boot() I have:
Carbon::serializeUsing(function ($carbon) {
return $carbon->format('Y-m-d\TH:i:s.uP T');
});
But all the dates are still returning in the format Y-m-d i:s:u
What am I doing wrong?
Thank you.
Please or to participate in this conversation.