0

When validating nested arrays with the same keys and rules, an incorrect error message will be picked up, for example, if the rules are:

$rules = [ 'elem.*.test' => 'required', 'elem.*.subitem.test' =>
'required', ];

and the messages:

$messages = [ 'elem.*.test.required' => 'top level item required', 'elem.*.subitem.test.required' => 'sub item required', ];
2
  • Can you show your regex? Commented Oct 7, 2018 at 20:45
  • @MaratBadykov it's $pattern = str_replace('*', '.*', $pattern); Commented Oct 7, 2018 at 20:46

2 Answers 2

2

Str::is() is called in FormatsMessages::getFromLocalArray().

You can't use

str_replace('*', '[^.]*', $sourceKey) 

because it gets escaped by preg_quote().

You could add a

$wildcard = '.*'  

parameter to Str::is() and override it with '[^.]*'

Sign up to request clarification or add additional context in comments.

Comments

0

This is a known issue: https://github.com/laravel/framework/issues/22499

You can fix it by swapping the messages:

$messages = [
    'elem.*.subitem.test.required' => 'sub item required',
    'elem.*.test.required' => 'top level item required'
];

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.