protected function serializeDate(DateTimeInterface $date)
{
return date_format($date, 'Y-m-d');
}
Feb 14, 2022
3
Level 3
Changing displayed date format - serializeDate not working?
In my model I have $casts to format the date for database insertion:
protected $casts = [
'updated_at' => 'datetime:Y-m-d H:i:s',
]
and below that I added serializeDate to display the date in a different format whenever displayed on the website:
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d');
}
But still, the dates shown are as Y-m-d H:i:s and not Y-m-d
Edit: This is how I actually insert a row with date to the database for example:
$model->updated_at = date('Y-m-d H:i:s');
in the migration this is how it's defined:
$table->dateTime('updated_at')->nullable();
Please or to participate in this conversation.