Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default Rules conflicting error message (email Rule) #161

Open
michaelthedev opened this issue Apr 3, 2024 · 0 comments
Open

Default Rules conflicting error message (email Rule) #161

michaelthedev opened this issue Apr 3, 2024 · 0 comments

Comments

@michaelthedev
Copy link

I have the same issues as this #143 (comment)

Found this in Validation.php

$messageKeys = [

As well as this

if (isset($this->messages[$key])) {

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant