validation
validation copied to clipboard
Default Rules conflicting error message (email Rule)
I have the same issues as this https://github.com/rakit/validation/issues/143#issue-1020226094
Found this in Validation.php
https://github.com/rakit/validation/blob/ff003a35cdf5030a5f2482299f4c93f344a35b29/src/Validation.php#L399
As well as this https://github.com/rakit/validation/blob/ff003a35cdf5030a5f2482299f4c93f344a35b29/src/Validation.php#L420
My fix:
- I added a new key as the first value in
$messageKeys
$messageKeys = [
'*'.$this->messageSeparator.$ruleKey, // new value
$attributeKey.$this->messageSeparator.$ruleKey,
$attributeKey,
$ruleKey
];
- I added to my custom messages to match the new value
$validation = $validator->validate($data, $rules, [
'required' => ':attribute is required',
'*:unique' => ':attribute already exists', // new custom message
'email' => ':attribute must be a valid email address',
'numeric' => ':attribute must be numeric',
'in' => ':attribute must be one of :allowed_values',
]);
This was the first messages it picks on (Line #421) is the custom message and it breaks the loop. The fix work for any other custom rule as long as it matches *:{$ruleKey}
It's a temporary fix and not a very good cause I had to edit files file /vendor folder. If you could look into this, I'd also be happy to create a PR if I find a better solution later on