filament-editorjs
filament-editorjs copied to clipboard
After save error Array to string conversion
After save error Array to string conversion(
Assuming you want to store the data from the editor.js component in a json or string based database column, you have to convert the data.
protected function mutateFormDataBeforeSave(array $data): array
{
$data['content'] = json_decode($data['content']);
return $data;
}
Add this to the Create-Class for your Filament Resource. Same goes for the Edit-Class and you have to do the reverse for the 'Edit' and 'View' class.
I had this issue - was trying to store the JSON data in a JSON field in MySQL.
Forgot to add the array cast to the Laravel model.
The following fixed this issue for me!
protected $casts = [
'content' => 'array',
];
I had this issue - was trying to store the JSON data in a JSON field in MySQL.
Forgot to add the array cast to the Laravel model.
The following fixed this issue for me!
protected $casts = [ 'content' => 'array', ];
This is actually the better solution compared to mine, as I learned in the meantime