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?
You don't have to increase it in Laravel, you have to increase it in PHP. In your php. ini there is a value that sets the maximum filesize PHP will accept. You have to talk to your hoster (if you don't manage your webserver yourself) that you need bigger filesizes.
Laravel Form Request class comes with two default methods auth() and rules() . You can perform any authorization logic in auth() method whether the current user is allowed to request or not. And in rules() method you can write all your validation rule.
But the laravel validator for "max" calculates size in KB not in MB. laravel.com/docs/5.1/validation#rule-maxlaravel.com/docs/5.1/validation#rule-size
In your Form Request files or validate () method you can pass array with this parameter: The last part means that size should be not more than 20 MB (20000 kB). But that may be not enough, cause file restrictions exist not only on Laravel application level. There are two settings related to max size in php.ini file.
[ 'image' => 'required|mimes:jpeg,bmp,png|size:20000', ] The last part means that size should be not more than 20 MB (20000 kB). But that may be not enough, cause file restrictions exist not only on Laravel application level. There are two settings related to max size in php.ini file. Here they are with their default values:
Laravel's built-in validation rules each has an error message that is located in your application's lang/en/validation.php file. Within this file, you will find a translation entry for each validation rule. You are free to change or modify these messages based on the needs of your application.
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'
];
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With