I have a Laravel Model named CostingSheetFabric with several date attributes defined in the $dates property, such as customer_start_date, customer_cancel_date, earliest_start_date, and earliest_cancel_date. I'm looking to customize the date format for these attributes when they are retrieved from the database.
I've tried using the asDateTime method in my model like this:
This seems not work for my use case, but I wanted to seek advice from the community. Is using asDateTime a recommended approach for customizing the date format in Laravel models, especially when dealing with multiple date attributes?
protected function asDateTime($value)
{
return parent::asDateTime($value)->format('Y-m-d');
}
following are not possible a model may have 35 date columns
protected $dates = [
'custom_date',
];
public function getStartDateAttribute($value)
{
return Carbon::parse($value)->format("Y-m-d");
}
tired this but does not working
asDateTime()is something you have written, is that right?