I am wondering if I can create a custom validation message for a specific field. For example i have a field named firstname, laravel so the validation error message with the if firstname (not capital letters and all together) so it looks bad. I want to create a specific message to just this field and it has to be on the validation.php because my site has different languages. Is it possible?
And if I have a field called email? I know email is already a validation message, so can I create a custom validation message to just the fields called email. Without matter if they have the email validation condition.
Yes, You can.
Use this custom message to add your custom message specific to a field
//field_rule => 'your message'
$messages = array(
'email_required' => 'The :attribute field is required.'
);
Yes, you can use this custom message like this way:
$messages = [
'required' => 'The :attribute field is required.',
'birthdate.required' => 'The BIRTHDATE field is required.'
];
$validator = Validator::make($request->all(), [
'name' => 'required',
'birthdate' => 'required',
], $messages);
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