Skip to content
Advertisement

How to give custom field name in laravel form validation error message

I was trying form validation in laravel. I have a input text field in my form called ‘Category’ and i’m given the field name as ‘cat’ as short.

And i defined the validation rules like this.

JavaScript

When the validation fails i’m getting error message like this

JavaScript

But i want to display it as “The category field is required” instead of ‘cat’.
How can i change ‘cat’ to ‘Category’ in error message ?.

Advertisement

Answer

You can specify custom error message for your field as follows.

JavaScript

Please see Custom Error Messages section in laravel documentation for more information.

Or you can keep a mapping for your field names like below. And you can set those into you validator. So you can see descriptive name instead of real field name.

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