I have 2 fields (started_at and ends_at), and I want to format them
For that, I use this accessor :
public function getStartedAtAttribute($value): string
{
return Carbon::parse($value)->format('Y-m-d\TH:i');
}
This is working for input with "\T" but not working for simple text
If I remove "\T", this is not working for input (type = datetimelocal)
How can I differentiate input or simple text ?
Thanks in advance for your help
CodePudding user response:
You can define the default format date on your model by using the cast array
protected $casts = [
'started_at' => 'datetime:Y-m-d',
];