I am using laravel 5.1. I have a summernotejs form element. I have successfully created a custom validation rule that takes HTML code from form input, breaks tags, and invokes strlen()
text content. Therefore, I can see the length of the message without any tags in it.
This is my validation rule:
Validator::extend('strip_min', function ($attribute, $value, $parameters, $validator) {
return strlen(strip_tags($value)) >= $parameters[0];
});
I invoke the validation rule by specifying: strip_min:10
or strip_min:20
, etc., with the number being the minimum string length after the tags are removed,
I want to add a custom message, indicating that the length of the content should be at least n
characters.
Laravel's documentation on this aspect is useless. I opened a file validation.php
containing all the error messages.
I added a key strip_min
to the message array with the message:The :attribute must be at least :min characters.
When I test it, I get an error message:
The notice must be at least :min characters.
How to convert :min
to the number specified in the validation rule? I read the documentation , but this is everywhere, and I cannot figure out how easy it is to replace: min with the given number.