Ad

Different Error Messages For Same Vaildation Keyword In Laravel

- 1 answer

I need for the validation keyword 'unique' two different error messages. How to do this? Is there any function for unique which I can copy and rename it?

'unique'               => 'The :Attribute has already been taken.',

Thank you

Ad

Answer

Copied from https://laravel.com/docs/5.6/validation#custom-error-messages

Specifying A Custom Message For A Given Attribute

Sometimes you may wish to specify a custom error messages only for a specific field. You may do so using "dot" notation. Specify the attribute's name first, followed by the rule:

$messages = [
    'email.required' => 'We need to know your e-mail address!',
];

Replace email with the field name and required with unique.

Ad
source: stackoverflow.com
Ad