Better control for nested wildcard behavior with the distinct validation rule #42823
Unanswered
joelclermont
asked this question in
Ideas
Replies: 1 comment
-
I ran into the same issue as @joelclermont and found the default wildcard expansion behavior to be quite surprising and unexpected. I agree that using something like |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I bumped into something I found a bit unintuitive with nested wildcards.
If we have a rule like this
'field.*.*' => ['distinct']
And data like this
'field' => [[1,2,3], [4,5,6], [1,4]]
I would have expected it to pass the validation rule because each array has internally distinct values. But because of how wildcard expansion works, it flattens those fields into a single array
[1,2,3,4,5,6,1,4]
for thedistinct
check, which fails validation.This can be worked around in a few different ways. (I wrote this up more thoroughly here)
Additionally, I realize that some people might rely on this behavior, and changing it would be a backward compatibility break, but it still strikes me as potentially confusing. I did a very small informal poll among other Laravel devs, and they all assumed
distinct
would operate on each individual array of values, not a flattened set of values.I'm not sure what a better solution is. I thought maybe a different character like
field._.*
to more explicitly define where you want wildcard expansion to limit flattening.Am I alone in thinking this could be improved? Is there a better idea for how to explicitly define this?
Beta Was this translation helpful? Give feedback.
All reactions