skip to Main Content

I use Laravel Filament in my project. When I create an input as follows:

TextInput::make("title")->filled()

This shows a notification when I try to submit with an empty title field.

But same filled() function doesn’t work with FileUpload. When I submit form without image, form proceeds without a notification. What am I missing?

FileUpload::make('image')
                ->columnSpan('full') 
                ->filled()
                ->disk('public')
                ->directory('gallery')
                ->visibility('public')
                ->imageResizeMode('force')
                ->imageCropAspectRatio('8:5')
                ->imageResizeTargetWidth('800')
                ->imageResizeTargetHeight('500')
                ->image()
                ->imageEditor()

2

Answers


  1. Try using nullable method, It gives you the same popup as filled

    But it adds the required CSS class after the label.

    FileUpload::make('image')
        ->columnSpan('full')
        // replace filled with nullable
        ->nullable(false)
        ->disk('public')
        ->directory('gallery')
        ->visibility('public')
        ->imageResizeMode('force')
        ->imageCropAspectRatio('8:5')
        ->imageResizeTargetWidth('800')
        ->imageResizeTargetHeight('500')
        ->image()
        ->imageEditor(),
    
    
    Login or Signup to reply.
  2. If you want to validate a FileUpload field to ensure that it contains a file, you can use the required() validation rule

    FileUpload::make('image')
        ->columnSpan('full')
        ->required()
        ->disk('public')
        // the rest of your code
        ;
    

    or a custom validation rule named ImageRequired.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search