Skip to content

Comments

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

Merged
taylorotwell merged 5 commits intolaravel:12.xfrom
markusheinemann:12.x
Jan 9, 2026
Merged

allow precognitive requests to use wildcards with array validations (#57437)#57486
taylorotwell merged 5 commits intolaravel:12.xfrom
markusheinemann:12.x

Conversation

@markusheinemann
Copy link
Contributor

@markusheinemann markusheinemann commented Oct 22, 2025

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 :)

@timacdonald
Copy link
Member

@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.

@markusheinemann
Copy link
Contributor Author

markusheinemann commented Nov 6, 2025

@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.

@timacdonald
Copy link
Member

@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.

@pascalbaljet
Copy link
Member

Thanks @markusheinemann for the PR! I've updated it based on @timacdonald's feedback.

Example with nested object

$rules = [
    'profile' => 'required|array',
    'profile.username' => 'required|string',
    'profile.email' => 'required|email',
];
Precognition-Validate-Only Validates
profile.* profile.username and profile.email
profile.username profile.username only

Example with nested arrays

$rules = [
    'users' => 'required|array',
    'users.*.name' => 'required|string',
    'users.*.email' => 'required|email',
];
Precognition-Validate-Only Validates
users.* nothing
users.*.* users.*.name and users.*.email
users.*.name users.*.name only
users.1.email users.*.email for index 1 only

@pascalbaljet pascalbaljet marked this pull request as ready for review January 9, 2026 13:27
@taylorotwell taylorotwell merged commit dc77c09 into laravel:12.x Jan 9, 2026
70 checks passed
@markusheinemann
Copy link
Contributor Author

markusheinemann commented Jan 10, 2026

@pascalbaljet Thanks for the completion! Should we update the docs for this change?

@pascalbaljet
Copy link
Member

@pascalbaljet Thanks for the completion! Should we update the docs for this change?

Yes, I've opened a PR: laravel/docs#10989

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.

CanBePrecognitive Trait dose not consider Validation Rules for Arrays

4 participants