Date Serialization
Customizing The Default Date Format
You may customize the default serialization format by overriding the serializeDate
method:
protected function serializeDate(DateTimeInterface $date)
{
return $date->format('Y-m-d');
}
iCustomizing The Date Format Per Attribute
You may customize the serialization format of individual Eloquent date attributes by specifying the date format in the cast declaraton:
protected $casts = [
'birthday' => 'date:Y-m-d',
'joined_at' => 'datetime:Y-m-d H:00',
];
To know more about cast declaration visit our bajarangisoft site.