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

secondman's avatar

Strange Date Strings in Vue with Laravel 7

I'm using Vue with Laravel 7 and Inertia and my dates are showing up like so:

created_at: "2020-05-12T03:47:41.000000Z"

If I die and dump the model before it gets to Vue they look like normal datetime strings:

"created_at" => "2020-05-11 20:47:41"

I've tried casting them as strings ... looked through all of the Inertia code ...

I first noticed this when updating Carbon, so maybe this is more of a Carbon issue than Laravel or Vue?

Any help appreciated.

0 likes
2 replies
SilenceBringer's avatar
Level 55

Hi @vkronlein by default created_at is casted as date, so when you get it it's Carbon instance. "2020-05-12T03:47:41.000000Z" is string presentation of carbon instance. So, you need to format the date before sending it to Vue, like

$model->created_at->format('Y-m-d H:i:s');
secondman's avatar

@silencebringer

I knew they were cast as Carbon instances, hence my discussion of it in the question, I've just never seen them needing to recast unless you wanted to change the default format to say m/d/y or something.

I've cast them in model like so:

'created_at' => 'datetime:Y-m-d H:i:s',

Works a charm.

Thanks for the heads up.

Please or to participate in this conversation.