Skip to content

[9.x] Allow validator messages to use nested arrays - #43981

Merged
taylorotwell merged 4 commits into
laravel:9.xfrom
ollieread:form-request-custom-message-array
Sep 5, 2022
Merged

taylorotwell merged 4 commits into
laravel:9.xfrom
ollieread:form-request-custom-message-array

Conversation

@ollieread

@ollieread ollieread commented Sep 2, 2022 •

Copy link
Copy Markdown
Contributor

This PR allows for validator messages to be nested without the dot notation.

Here's an example of the current way of providing custom messages.

[
   'attribute.rule1' => 'message1',
   'attribute.rule2' => 'message2',
   'attribute.rule3' => 'message3',
   'attribute.rule4' => 'message4',
   'attribute.rule5' => 'message5',
]

This PR makes it possible to nest the rule => message elements.

[
   'attribute' => [
       'rule1' => 'message1',
       'rule2' => 'message2',
       'rule3' => 'message3',
       'rule4' => 'message4',
       'rule5' => 'message5',
    ]
]

The idea is that it makes it easier to read and identify.

@nunomaduro nunomaduro changed the title Allow validator messages to use nested arrays [9.x] Allow validator messages to use nested arrays Sep 2, 2022
@taylorotwell
taylorotwell merged commit 78289b4 into laravel:9.x Sep 5, 2022
@siarheipashkevich

Copy link
Copy Markdown
Contributor

@ollieread will it work for FormRequest attributes?

@ollieread

ollieread commented Sep 5, 2022 •

Copy link
Copy Markdown
Contributor Author

@ollieread will it work for FormRequest attributes?

@siarheipashkevich that's specifically why I created it, working for all validators was a side effect.

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

Successfully merging this pull request may close these issues.

3 participants