What happened?
I’m using the EditorjsTextField component in my Filament form.
When I try to save an article, I get the following error:
Array to string conversion (Connection: mysql, Host: 127.0.0.1, Port: 3306, Database: laravel, SQL: insert into `blog_articles` ...)
It seems that the field returns a JSON string, but my model/migration setup might be incorrect.
I’m not sure what the recommended database column type and model cast should be for EditorjsTextField.
How to reproduce the bug
How to reproduce the bug
- Create a migration with a
json column for content:
Schema::create('blog_articles', function (Blueprint $table) {
$table->id();
$table->string('title');
$table->json('content'); // or longText?
$table->json('content_images')->nullable();
$table->timestamps();
});
- Define the model:
class Article extends Model implements HasMedia
{
use ModelHasEditorJsComponent,InteractsWithMedia;
protected $table = 'blog_articles';
protected $fillable = ['title', 'description', 'keywords', 'content', 'status', 'user_id'];
protected $casts = [
'content' => 'array', // or string?
];
}
- Use
EditorjsTextField in the Filament form:
EditorjsTextField::make('content')
->label('Content')
->required()
->columnSpanFull();
- Try to create a new article with some content.
Expected behavior
I would like to know the correct way to define the database column type and the model cast for EditorjsTextField.
Should the column be json, text, or longText?
Should the cast be string or array?
Could you please provide an example of a recommended model + migration setup for this field?
Thanks a lot for your help and for maintaining this package!
### Package Version
2.3
### PHP Version
8.4
### Laravel Version
12
### Which operating systems does with happen with?
Windows
### Notes
_No response_
What happened?
I’m using the
EditorjsTextFieldcomponent in my Filament form.When I try to save an article, I get the following error:
It seems that the field returns a JSON string, but my model/migration setup might be incorrect.
I’m not sure what the recommended database column type and model cast should be for
EditorjsTextField.How to reproduce the bug
How to reproduce the bug
jsoncolumn forcontent:EditorjsTextFieldin the Filament form:Expected behavior
I would like to know the correct way to define the database column type and the model cast for
EditorjsTextField.Should the column be
json,text, orlongText?Should the cast be
stringorarray?Could you please provide an example of a recommended model + migration setup for this field?
Thanks a lot for your help and for maintaining this package!