Skip to content

Commit 8c05067

Browse files
[12.x] Add documentation for "Rule::contains" (#10457)
* Add documentation for new "contains" validation rule * Update validation.md --------- Co-authored-by: Taylor Otwell <taylor@laravel.com>
1 parent 0272b78 commit 8c05067

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

‎validation.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1356,7 +1356,20 @@ You may also pass a custom confirmation field name. For example, `confirmed:repe
13561356
<a name="rule-contains"></a>
13571357
#### contains:_foo_,_bar_,...
13581358

1359-
The field under validation must be an array that contains all of the given parameter values.
1359+
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:
1360+
1361+
```php
1362+
use Illuminate\Support\Facades\Validator;
1363+
use Illuminate\Validation\Rule;
1364+
1365+
Validator::make($data, [
1366+
'roles' => [
1367+
'required',
1368+
'array',
1369+
Rule::contains(['admin', 'editor']),
1370+
],
1371+
]);
1372+
```
13601373

13611374
<a name="rule-current-password"></a>
13621375
#### current_password

0 commit comments

Comments
 (0)