3

I am trying to add a custom validation message using the below code,

$validator = Validator::make(
            $user,
            [
                'first_name' => 'required|min:2',
                'email'      => [
                    'required',
                    'email',
                    Rule::notIn(array_column(Customer::getEmails(), 'email'))
                ]
            ],
            ['email.required' => 'Email is required (Custom message)']);

I have added a custom message for email required validation. No issues there.

For Rule::notIn validation, currently it is returning The email is invalid. How can I add a custom message in this case?

Unable to find anything related in Laravel docs about this.

2
  • Possible duplicate of Custom message laravel Validation Commented Jan 9, 2019 at 9:44
  • 1
    @MasivuyeCokile This is a whole different case. Please read it completely. Commented Jan 9, 2019 at 9:45

1 Answer 1

2

Try this:

$validator = Validator::make(
        $user,
        [
            'first_name' => 'required|min:2',
            'email'      => [
                'required',
                'email',
                Rule::notIn(array_column(Customer::getEmails(), 'email'))
            ]
        ],
        [
            'email.required' => 'Email is required (Custom message)',
            'email.email' => 'Your custom message here',
            'email.not_in' => 'Your custom message here',
        ]
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.