filament-editorjs icon indicating copy to clipboard operation
filament-editorjs copied to clipboard

After save error Array to string conversion

Open mr-mister-bit opened this issue 1 year ago • 3 comments

After save error Array to string conversion(

mr-mister-bit avatar Mar 12 '23 22:03 mr-mister-bit

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.

firlus avatar Apr 27 '23 18:04 firlus

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',
];

cbowofrivia avatar Aug 17 '23 13:08 cbowofrivia

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

firlus avatar Aug 17 '23 13:08 firlus