Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Bagmaz's avatar
Level 22

Filamentphp Hidden default value

public static function getForm(): array
    {
        return [
            Builder::make('content')
                ->translateLabel()
                ->columnSpanFull()
                ->blocks([
                    Builder\Block::make('images')
                        ->translateLabel()
                        ->schema([
                            Hidden::make('type')
                                ->default('images'),
                            FileUpload::make('body')
                                ->label('Image')
                                ->maxFiles(4)
                                ->translateLabel(),
                        ]),
                    Builder\Block::make('content')
                        ->translateLabel()
                        ->schema([
                            Hidden::make('type')
                                ->default('body'),
                            RichEditor::make('content')
                                ->label('Content')
                                ->translateLabel(),
                        ])
                ]),
        ];
    }
SQLSTATE[HY000]: General error: 1364 Field 'type' doesn't have a default value
INSERT INTO
  `contents` (`post_id`, `updated_at`, `created_at`)
VALUES
  (1, 2024 -02 -15 23: 05: 20, 2024 -02 -15 23: 05: 20)
0 likes
1 reply
Bagmaz's avatar
Level 22

I watched this video (https://www.youtube.com/watch?v=sQ9taf7tnjg) and found my mistake. the correct form is like this:

protected $casts = [
        'content' => 'array',
    ];
Section::make()
                        ->schema([
                            Builder::make('content')
                                ->translateLabel()
                                ->columnSpanFull()
                                ->blocks([
                                    Builder\Block::make('section_title')
                                        ->translateLabel()
                                        ->schema([
                                            TextInput::make('title')
                                                ->translateLabel()
                                                ->columnSpan(2)
                                                ->required(),
                                            Select::make('level')
                                                ->translateLabel()
                                                ->options([
                                                    'text-sm' => __('Small'),
                                                    'text-base' => __('Normal'),
                                                    'text-lg' => __('Large'),
                                                    'text-2xl' => __('Extra large'),
                                                ])
                                                ->required(),
                                        ])->columns(3),
                                    Builder\Block::make('section_content')
                                        ->translateLabel()
                                        ->schema([
                                            RichEditor::make('content')
                                                ->translateLabel()
                                                ->required()
                                                ->disableToolbarButtons([
                                                    'codeBlock',
                                                    'attachFiles',
                                                ]),
                                        ]),
                                    Builder\Block::make('section_image')
                                        ->translateLabel()
                                        ->schema([
                                            FileUpload::make('image')
                                                ->translateLabel()
                                                ->imageEditor()
                                                ->image()
                                                ->optimize('webp')
                                                ->required(),
                                        ]),
                                ])->collapsible(),
                        ]),

Please or to participate in this conversation.