0

Based on the Laravel's documentation, the way to edit error message is like this:

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

$validator = Validator::make($input, $rules, $messages);

But what if the rule is using Rule class?

For example:

$rules = [
    'img_type'      => ['required', Rule::in(['png', 'jpeg', 'gif'])],
];

$messages = [
    'img_type.{what-to-type-here-for-Rule::in}' => 'Invalid image type',
];

$validator = Validator::make($input, $rules, $messages);

As the example above, img_type.{what-to-type-here-for-Rule::in}, I don't know how to specify the custom error message for Rule::in...

1 Answer 1

4

The rule is just called in. So this is what you have to use.

$messages = [
    'img_type.in' => 'Invalid image type',
];

Exactly as it is defined in the default translations.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.