-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[9.x] Added support for index and position placeholders in array validation messages #41123
Conversation
Not sure why the builds are failing. Like I can read why, but can't see if and what I should change to fix it. |
@gguney both changes are made. Thank you. Any idea why the PHP testing fails? |
Seems to be all passing now so no issues there |
What if the item is more deeply nested? |
Perhaps something like this?
I'm all ears if you have a different approach. |
This has been attempted before in #35754. You might want to check it out. |
Thanks, will have a read through it and see what I can come up with. |
I've updated this so that more deeply nested indexes / positions can be accessed via $data = [
'users' => [
[
'name' => 'Taylor Otwell',
'attributes' => [
'foo',
],
],
[
'name' => '',
'attributes' => [
'foo',
'bar',
1,
],
],
]
];
$validator = Validator::make($data, [
'users.*.name' => 'required|string',
'users.*.attributes.*' => 'string',
], [
'users.*.name.required' => ':index :position',
'users.*.attributes.*.string' => ':first-index :first-position :second-index :second-position',
]); |
Adds a backward compatible change that enables a developer to use
:index
or:pos
in the message for array inputs. Assumes 0 or 1 respectively if it's not an array input.Discussed in #32977