How to change Laravel Validation message for max file size in MB instead of KB?

Glad To Help picture Glad To Help · Dec 22, 2015 · Viewed 8.6k times · Source

Laravel comes with this validation message that shows file size in kilobytes:

file' => 'The :attribute may not be greater than :max kilobytes.',

I want to customize it in a way that it shows megabytes instead of kilobytes. So for the user it would look like:

"The document may not be greater than 10 megabytes."

How can I do that?

Answer

Pratik Kaje picture Pratik Kaje · Dec 22, 2015

We might be on different page, here is what I am trying to say. I hope this helps. Cheers!

public function rules()
{
    return [
        'file' => 'max:10240',
     ];
}

public function messages()
{
    return [
        'file.max' => 'The document may not be greater than 10 megabytes'
    ];
}