1

In my AppServideProvider's boot method I've set a custom validation rule for cyrillic. Here is what it lookes like:

public function boot()
{
    Validator::extend('cyrillic', function ($attribute, $value, $parameters, $validator) {
        return preg_match('/[А-Яа-яЁё]/u', $value);
    });
}

It works as expected. However if the validation doesn't pass because of latin input I get the error message 'validation.cyrillic'. How can I fix that? How can I pass a custom message to my 'cyrillic' validation rule?

1 Answer 1

1

If you want to define it globally, you need to edit the validation file or files, which is/are located in resources/lang/LANG/validation.php where LANG is whatever language you want to define is.

For instance, for the English ones, open the file resources/lang/en/validation.php and add your message like below.

return [
    'accepted'             => 'The :attribute must be accepted.',
    'active_url'           => 'The :attribute is not a valid URL.',
    // Add yours to somewhere in the first level of the array
    'cyrillic'             => 'The :attribute is not Cyrillic.'
]

For locally, you can define it within a Request.

public function messages()
{
    return [
        'cyrillic' => 'The :attribute is not Cyrillic.'
    ];
}
Sign up to request clarification or add additional context in comments.

1 Comment

Worked like a charm. Cheers!

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.