#RichEditor content is ignored

4 messages · Page 1 of 1 (latest)

scenic kestrel
#

I have a simple schema:

public static function configure(Schema $schema): Schema
    {
        return $schema
            ->components([
                Hidden::make('editor_id')
                    ->default(auth()->id()),

                TextInput::make('title')
                    ->label(__('Title'))
                    ->required()
                    ->maxLength(255),

                DateTimePicker::make('published_at')
                    ->label(__('Published at'))
                    ->displayFormat('d.m.Y, H:i')
                    ->native(false)
                    ->seconds(false)
                    ->nullable(),

                RichEditor::make('body')
                    ->label(__('Body'))
                    ->columnSpan('full'),

                Toggle::make('is_active')
                    ->label(__('Active'))
                    ->default(true),
            ]);
    }

When I save this I got an QueryException because the rich editor field (body) is missing:
General error: 1364 Field 'body' doesn't have a default value (Connection: mysql, SQL: insert into `announcements` (`editor_id`, `title`, `published_at`, `is_active`, `updated_at`, `created_at`) values (1, zuguz, ?, 1, 2025-09-25 17:31:35, 2025-09-25 17:31:35))

If I replace the RichEditor with a Textarea field without any other changes it workes.

modest hamletBOT
#

To help others find answers, you can mark your question as solved via Right click solution message -> Apps -> ✅ Mark Solution

scenic kestrel
#

Oh, it has something to do with the media handling.
The rich editor works if I remove

public function setUpRichContent(): void
    {
        $this->registerRichContent('body')
            ->fileAttachmentsDisk('public')
            ->fileAttachmentProvider(SpatieMediaLibraryFileAttachmentProvider::make()
                ->collection('announcements')
            );
    }

from the model. But I want to handle the media via Spatie Media Library

scenic kestrel
#

ok, wow. I solved it. The body column has to be nullable even the field is required - This is mentioned in the filament spatie media library documention but can easily be overlooked here: https://filamentphp.com/plugins/filament-spatie-media-library#using-media-library-for-rich-editor-file-attachments

Using SpatieMediaLibraryFileAttachmentProvider requires that the rich content attribute (content in this example) must be defined as nullable in database.

Filament

Filament support for Spatie's Laravel Media Library package.