F
Filament6mo ago
Tazeen

Custom validation message for File-upload

I am trying to provide custom validation messages for the acceptedFileTypes to prevent uploading invalid formats. I want to restrict the invalid file upload while uploading the file itself hence I am not using rules method. But it is not taking the custom message that I am giving, rather it is taking the default messages provided by filament. Can anyone help me regarding this? Below is the code that I am using ->acceptedFileTypes(['image/jpeg','image/jpg']) ->label('File') ->required() ->maxSize(5120) ->default(asset('public/images/VehiclesMngt.jpeg'))
->validationMessages([
'acceptedFileTypes'=>'Please upload only jpeg or jpg images', 'maxSize' => 'The uploaded file cannot be larger than 5mb' ]),
No description
1 Reply
Vp
Vp6mo ago
I think it should be like this according to https://laravel.com/docs/11.x/validation#rule-mimetypes
->validationMessages([
'mimetypes'=>'Please upload only jpeg or jpg images',
'max' => 'The uploaded file cannot be larger than 5mb'
])
->validationMessages([
'mimetypes'=>'Please upload only jpeg or jpg images',
'max' => 'The uploaded file cannot be larger than 5mb'
])
Want results from more Discord servers?
Add your server