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

timgavin's avatar
Level 11

Custom validation message not showing

I'm working on a form which allows multiple file uploads. Everything is working correctly, however when the file is too large I see the default Laravel validation message instead of the custom message.

#[Validate([
    'photos' => 'required',
    'photos.*' => 'mimes:jpg,png,gif|max:12288',
],
    message:[
        'photos.*.mimes' => 'You can only upload JPGs, PNGs, and GIFs',
        'photos.*.max' => 'Images cannot be larger than 12MB'
    ]
)]
public $photos = [];

I see this default error message: The image must not be greater than 12288 kilobytes, instead of my custom message: Images cannot be larger than 12MB.

When updating my value to 10240 I still see Livewire is validating for 12MB, instead of my 10, so are my rules being ignored?

This is what I have in config/livewire.php

'temporary_file_upload' => [
    'disk' => null, 
    'rules' => ['file', 'mimes:jpg,png,gif', 'max:12288'],
    'directory' => null, 
    'middleware' => null, 
    'preview_mimes' => ['png', 'gif', 'jpg', 'jpeg'],
    'max_upload_time' => 5, 
],
0 likes
7 replies
jlrdw's avatar

Did you clear the various cache after making changes?

timgavin's avatar
Level 11

@jlrdw Yes. I've been thinking about this and I believe the validation is happening before it even hits the component, which I think is how Livewire is intended to work. Haven't found a way to add custom error messages to Livewire's config though, if that's even the solution...

jlrdw's avatar

@timgavin I am pretty sure to validate files, you use the regular laravel file validation. I'm still not sure about the custom message.

But the documentation shows a return for messages:

https://laravel.com/docs/11.x/validation#customizing-the-error-messages

public function messages(): array
{
    return [
        'title.required' => 'A title is required',
        'body.required' => 'A message is required',
    ];
}

Sometimes custom validation can be a bit tricky to setup.

timgavin's avatar
Level 11

@jlrdw I've tried this as well, using both methods and properties and nothing works.

Snapey's avatar

@jlrdw not with Livewire. It has its own rules for uploaded files.

Snapey's avatar

have you considered creating a translation, but from english to english?

timgavin's avatar
Level 11

@Snapey I'm not sure how that would work? Regardless, I ended up increasing the upload file size in Livewire.config so that it reaches my component, so that the component error message is shown, which is more human readable. not the best solution... I'm gonna head over to Livewire's repo and see what we can do.

Please or to participate in this conversation.