What happened?
When using the Flatpickr component with multiplePicker() or rangePicker() in FilamentPHP 4 EditRecord forms, the component throws an "Array to string conversion" error during form hydration. The error occurs because FilamentPHP's DateTimeStateCast tries to process array data from the database as if it were a single datetime string.
The component works perfectly in CreateRecord forms but fails in EditRecord forms when existing array data is loaded from the database.
Environment
- PHP Version: 8.3.25
- Laravel Version: 12.29.0
- FilamentPHP Version: 4.x
Error Stack Trace
ErrorException - Array to string conversion
vendor/filament/schemas/src/Components/StateCasts/DateTimeStateCast.php:42
vendor/filament/schemas/src/Components/Concerns/HasState.php:375
vendor/filament/filament/src/Resources/Pages/EditRecord.php:116
How to reproduce the bug
Set up a model with array-cast fields:
// In your model
protected $casts = [
'dates' => 'array',
'schedule_date_range' => 'array',
];
Create Flatpickr fields in your form:
Flatpickr::make('dates')->multiplePicker(),
Flatpickr::make('schedule_date_range')->rangePicker()
Save a record with multiple dates or date range
Try to edit the record - Error occurs during form hydration
Package Version
5.0.0
PHP Version
8.3.25
Laravel Version
12.29.0
Which operating systems does with happen with?
No response
Notes
Expected Behavior
The EditRecord form should load existing array data and display it properly in the Flatpickr components, just like CreateRecord forms work when saving array data.
Actual Behavior
- CreateRecord: Works perfectly ✅
- EditRecord: Throws "Array to string conversion" error ❌
The error happens because:
- EditRecord loads array data from database
- Flatpickr extends DateTimePicker which uses DateTimeStateCast
- DateTimeStateCast expects string/datetime values, not arrays
- Conversion fails before custom hydration logic can run
Proposed Solution
The core issue is that DateTimePicker's state casting runs before custom hydration logic.
- Override state casting order in the component's setUp() method
- Extend Field directly instead of DateTimePicker to avoid datetime state casting
- Add array data detection in the hydration process before parent casting occurs
What happened?
When using the Flatpickr component with multiplePicker() or rangePicker() in FilamentPHP 4 EditRecord forms, the component throws an "Array to string conversion" error during form hydration. The error occurs because FilamentPHP's DateTimeStateCast tries to process array data from the database as if it were a single datetime string.
The component works perfectly in CreateRecord forms but fails in EditRecord forms when existing array data is loaded from the database.
Environment
Error Stack Trace
ErrorException - Array to string conversion
vendor/filament/schemas/src/Components/StateCasts/DateTimeStateCast.php:42
vendor/filament/schemas/src/Components/Concerns/HasState.php:375
vendor/filament/filament/src/Resources/Pages/EditRecord.php:116
How to reproduce the bug
Set up a model with array-cast fields:
Create Flatpickr fields in your form:
Save a record with multiple dates or date range
Try to edit the record - Error occurs during form hydration
Package Version
5.0.0
PHP Version
8.3.25
Laravel Version
12.29.0
Which operating systems does with happen with?
No response
Notes
Expected Behavior
The EditRecord form should load existing array data and display it properly in the Flatpickr components, just like CreateRecord forms work when saving array data.
Actual Behavior
The error happens because:
Proposed Solution
The core issue is that DateTimePicker's state casting runs before custom hydration logic.