Skip to content

[12.x] Add in_array_keys validation rule to check for presence of specified array keys #55807

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

Merged
merged 5 commits into from
May 26, 2025

Conversation

stevebauman
Copy link
Contributor

Description

This PR introduces a new validation rule called in_array_keys that validates whether an array contains at least one of the specified keys. It is named to follow the convention of existing rules (in_array and required_array_keys).

Purpose

While the required_array_keys rule exists which ensures all specified keys exist in an array, there is no built-in way to validate that an array has at least one of a given set of keys.

Usage

$validator = Validator::make($request->all(), [
    'config' => 'array|in_array_keys:api_key,access_token,oauth_token',
    'config.api_key' => 'nullable|string|min:32|max:64',
    'config.access_token' => 'nullable|string|min:40',
    'config.oauth_token' => 'nullable|string|starts_with:oauth_',
]);

Let me know if you'd like anything changed or adjusted! Thanks for your time 🙏

@shaedrich
Copy link
Contributor

shaedrich commented May 21, 2025

This PR introduces a new validation rule called in_array_keys that validates whether an array contains at least one of the specified keys. It is named to follow the convention of existing rules (in_array and required_array_keys).

Alternative possible naming:

  • possible_array_keys
  • allowed_array_keys

@taylorotwell taylorotwell merged commit 8b9f434 into laravel:12.x May 26, 2025
59 checks passed
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