Skip to content
Advertisement

Custom error message for Laravel validation rule: Dimensions

I’m trying to validate an image upload that looks like the following:

JavaScript

when the selected image too small then laravel shows error:

JavaScript

I think that message is not saying specifically that in which dimension the image small, eg: width or height.

I’m expecting error message like: The Admin Image width cannot be less than 600px and The Admin Image height cannot be less than 600px

here ‘Admin image’ is the attribute name & ‘600’ is the value I given in rules

So, I wanted to make a custom error message for min_width and max_widthin custom messages array on validation.php, that look like the following:

JavaScript

But unfortunately that doesn’t work & Laravel continues to show the default message.

Please understand that

I need 2 separate error message for dimensions:min_width=600 & dimensions:min_height=600

like I tried in the custom error messages array.

I know this is very simple but I’m doing something wrong.

Any help will be highly appreciated

Advertisement

Answer

Add the custom error message in validation.php as below:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement