Registering A Custom Validator Resolver
Next, you need to register your custom Validator extension:
Validator::resolver(function($translator, $data, $rules, $messages)
{
return new CustomValidator($translator, $data, $rules, $messages);
});
When creating a custom validation rule, you may sometimes need to define custom place-holder replacements for error messages. You may do so by creating a custom Validator as described above, and adding a
replaceXXX
function to the validator.protected function replaceFoo($message, $attribute, $rule, $parameters)
{
return str_replace(':foo', $parameters[0], $message);
}
If you would like to add a custom message "replacer" without extending the
Validator
class, you may use the Validator::replacer
method:Validator::replacer('rule', function($message, $attribute, $rule, $parameters)
{
//
});