Closed jagdtiger9 closed 1 year ago
If you wish to assign an error message to a specific field/attribute e.g. username
, prefix with the attribute name and a :
and then add the rule name (that uses dot separation). Otherwise if you set only on the rule name, then all errors will use that message.
For example: username => required|email|max:255
, may want a specific error message: username:email => 'usernames require a valid email address'
. That message would only be displayed against a field named username
.
Does that help?
Sry for bad exmaple code formatting And yeah, i read the doc inattentively, sry again \ TY very much!
No worries! Glad to be of help. If you have any further questions, don't hesitate to open an issue.
It looks like custom message key separator is ':'
class Validation { private AttributeBag $attributes; ... private string $separator = ':'; ... protected function resolveMessage(Attribute $attribute, Rule $rule, mixed $value): ErrorMessage { ... $messageKeys = [ $attributeKey . $this->separator . $ruleName, $attributeKey, $message->key(), ];
And doc uses '.'$factory->messages()->add('es', [ 'rule.required' => 'Se requiere :attribute', ]);