framework icon indicating copy to clipboard operation
framework copied to clipboard

allow precognitive requests to use wildcards with array validations (#57437)

Open markusheinemann opened this issue 2 months ago • 3 comments

This PR is a proposal to resolve #57437.

With this change, users can specify a wildcard to trigger all validation rules for an array field when using precognitive requests. Before the change the user had to specify all array validation rules manually in the Precognition-Validate-Only header. Now wildcards can specified to cover all array entries.

// Before
Precognition-Validate-Only: nested_array,nested_array.0.title,nested_array.1.title,nested_array.2.title
Precognition-Validate-Only: raw_array,raw_array.0,raw_array.1,raw_array.2

// After
Precognition-Validate-Only: nested_array,nested_array.*.title
Precognition-Validate-Only: raw_array,raw_array.*

PS. This is my first PR for Laravel so please forgive me mistakes. I appreciate any feedback :)

markusheinemann avatar Oct 22 '25 07:10 markusheinemann

@markusheinemann, what do you think about making this a little less strict and allow a * to match anything that isn't a .?

Just thinking it could be cool to do users.* and it match users.name and users.email.

Then you could do something like users.*.* to match users.1.name and users.1.email, etc.

timacdonald avatar Nov 06 '25 00:11 timacdonald

@timacdonald Totally agree. Would be a nice convenience feature...

Would we assume that user.* is the same as users.*.* but not as users.*.email? Or should we force that the wildcard only work at on level (e.g. to match users.names.first the wildcard users.*.* needs to be specified). I think the second way is more explicit.

I take a look into a adjusted implementation.

markusheinemann avatar Nov 06 '25 09:11 markusheinemann

@markusheinemann, I feel that the wildcard should not be greedy with dots, i.e., to match users.names.first the wildcard users.*.* needs to be specified.

timacdonald avatar Nov 10 '25 00:11 timacdonald