I have model, and it has several field names, and 'lastName' is among them.
In my FormRequest file, I have rules and messages for this field:
$rules = ['lastName.*' => 'lastName_fail: index'];
$messages = ['lastName.*lastName_fail' => This lastName has different value in DB!'];
When I am submitting a form, filling the 'lastName' field with intentionally 'wrong' value, it doesn't pass validation, and returns error message:
validation.last_name_fail
(which is not what's in $messages).
But when I change $rules and $messages to:
$rules = ['lastName.*' => 'lastname_fail: index'];
$messages = ['lastName.*lastname_fail' => This lastName has different value in DB!'];
(so the actual "rule" is now lowercase "lastname_fail"), it outputs what i want:
This lastName has different value in DB!
from this I may conclude that Laravel's validation rule name may be only lowercase.
Is it declared anywhere in documentation?
If so, maybe it helps someone.
It is not mentioned in the documentation. However, there is a naming pattern for both validation rule method name and rule name.
Rule Method Name:
It must have
validateprefix and the rest of it must be inCamel Case.Rule Name:
It will be in
lowercasewithout thevalidateprefix and each word will be separated by anunderscore.So if you want to add
alpha_dash_spacesvalidation rule then the corresponding method will be namedvalidateAlphaDashSpaces().