Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Custom validation messages to specific field in laravel

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.

like image 548
carloscc Avatar asked Mar 17 '23 10:03

carloscc


2 Answers

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.'
);
like image 102
Bhaskar Thammali Avatar answered Mar 22 '23 01:03

Bhaskar Thammali


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);
like image 44
Matheus Evangelista Avatar answered Mar 22 '23 01:03

Matheus Evangelista