8000 [12.x] Add documentation for "Rule::contains" by stevebauman · Pull Request #10457 · laravel/docs · GitHub
[go: up one dir, main page]

Skip to content

[12.x] Add documentation for "Rule::contains" #10457

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

8000
Merged
merged 2 commits into from
May 27, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add documentation for new "contains" validation rule
  • Loading branch information
stevebauman committed May 27, 2025
commit c4654f9c04182e1ecbbd58432866741ad97bd3c8
43 changes: 42 additions & 1 deletion validation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1356,7 +1356,48 @@ You may also pass a custom confirmation field name. For example, `confirmed:repe
<a name="rule-contains"></a>
#### contains:_foo_,_bar_,...

The field under validation must be an array that contains all of the given parameter values.
The field under validation must be an array that contains all of the given parameter values. Since this rule often requires you to `implode` an array, the `Rule::contains` method may be used to fluently construct the rule:

```php
use Illuminate\Support\Facades\Validator;
use Illuminate\Validation\Rule;

Validator::make($data, [
'roles' => [
'required',
'array',
Rule::contains(['admin', 'editor']),
],
]);
```

The `Rule::contains` method accepts arrays, collections, enums, and individual values:

```php
use App\Enums\Role;
use Illuminate\Validation\Rule;

// Using enums
'roles' => [
'required',
'array',
Rule::contains([Role::Admin, Role::Editor]),
],

// Using individual arguments
'roles' => [
'required',
'array',
Rule::contains('admin', 'editor'),
],

// Using collections
'roles' => [
'required',
'array',
Rule::contains(collect(['admin', 'editor'])),
],
```

<a name="rule-current-password"></a>
#### current_password
Expand Down
0