filamentphp / filament

A collection of beautiful full-stack components for Laravel. The perfect starting point for your next app. Using Livewire, Alpine.js and Tailwind CSS.
https://filamentphp.com
MIT License
19.11k stars 2.95k forks source link

BaseFileUpload.php: No custom validation message (for mimetypes) #12741

Closed pgerundt closed 6 months ago

pgerundt commented 6 months ago

Package

filament/forms

Package Version

v3.2.76

Laravel Version

v10.48.10

Livewire Version

v3.4.12

PHP Version

PHP 8.3.7

Problem description

Having an upload with a custom validation message:

Upload::make('logo')
    ->acceptedFileTypes([
        'image/png',
    ])
    ->validationMessages([
        'mimetypes' => 'THIS MESSAGE NEVER SHOWS',
    ]);

The custom validation message is not shown when uploading a file with incorrect mimetype.

Expected behavior

Message should be shown, but BaseFileUpload::getValidationRules() has validation messages missing:

https://github.com/filamentphp/filament/blob/3.x/packages/forms/src/Components/BaseFileUpload.php

            $validator = Validator::make(
                [$name => $files],
                ["{$name}.*" => ['file', ...parent::getValidationRules()]],
                [],
                ["{$name}.*" => $this->getValidationAttribute()],
            );

should be

            $validator = Validator::make(
                [$name => $files],
                ["{$name}.*" => ['file', ...parent::getValidationRules()]],
                ["{$name}.*" => $this->validationMessages],
                ["{$name}.*" => $this->getValidationAttribute()],
            );

Steps to reproduce

see description above

Reproduction repository

https://github.com/filamentphp/filament

Relevant log output

No response

github-actions[bot] commented 6 months ago

Hey @pgerundt! We're sorry to hear that you've hit this issue. 💛

However, it looks like you forgot to fill in the reproduction repository URL. Can you edit your original post and then we'll look at your issue?

We need a public GitHub repository which contains a Laravel app with the minimal amount of Filament code to reproduce the problem. Please do not link to your actual project, what we need instead is a minimal reproduction in a fresh project without any unnecessary code. This means it doesn't matter if your real project is private / confidential, since we want a link to a separate, isolated reproduction. That would allow us to download it and review your bug much easier, so it can be fixed quicker. Please make sure to include a database seeder with everything we need to set the app up quickly.

Also, it doesn't look like you've provided much information on how to replicate the issue. Please edit your original post with clear steps we need to take.