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

donpuerto's avatar

Mutated Date

I tried converting date into date mutators in Model. I was expecting result would be carbon timestamp format 2015-11-15 14:06:57 or Y-m-d H:i:s.

Surprisingly the result was 2015-11-15 and time set to 0:0:0.

How does this thing happen? Any idea?

Thanks.

0 likes
5 replies
braxton's avatar

It'd be super helpful if you post the code block that is getting/making the timestamps. I could possibly help you from there. I'm not too sure off the top of my head what would be wrong, as it seems like it returns the years, months, and days correctly, and not the hours, minutes, and seconds. So if I could take a look at your code that would help me through your problem tremendously.

donpuerto's avatar
donpuerto
OP
Best Answer
Level 4

@braxtonfair

What i am trying to do here, i want a carbon date from the form input.

Form

Form Date format was date('Y-m-d')

Storing into Database

Form

Setting up the model

Form

Result

Form

Database

Form As you can see, date was not formatted to Carbon

braxton's avatar

In your model, you are using

protected $date = ['published_at'];

Instead, it should be plural, as shown

protected $dates = ['published_at'];

Also, you are only getting the Year, Month, and Day, as shown here:

Form

{!! Form::date('published_at', 'Y-m-d', ['class' => 'form-control']) !!}

You create a Carbon date, make sure you are able to create it in your view, then do this:

Carbon::now()

Please or to participate in this conversation.