How are you passing the current value to the Datepicker? What format(s) does the Datepicker expect/support?
Datepicker & date accessor
Hi,
I've created a Model which has a datetime column called start.
I've written the following accessor:
/**
* Get the start.
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
*/
protected function start(): Attribute
{
return Attribute::make(
get: fn ($value) => Carbon::createFromFormat('Y-m-d H:i:s', $value)->format('d-m-Y H:i'),
);
}
It works, except when I'm on the Edit screen. The value in that case is empty, so I guess I need to modify the settings for the Datetime field / Datepicker.
I can't figure out what/where to edit in order to get the field prepopulated with the value from the database.
Already tried different settings for $casts, which currently is:
protected $casts = [
'start' => 'datetime',
];
@glennmulleners Use the cast or the accessor method; not both. I suggested the cast because this gives you a Carbon instance to work with - you can then format it differently in different contexts, whereas the accessor (as you have implemented it) will always give you a String.
Please or to participate in this conversation.