Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[11.x] create new "has" validation rule (#51348)
* create new "has" validation rule currently we have the "in" rule, which checks if given input is in a list of approved values. this new "has" rule is kind of the opposite of that. it checks that expected values are included in the given array of input. for example, assume you are setting up the ability to restrict access to certain IP addresses. you might setup some rules like this: ```php return [ 'allowed_ips' => ['present', 'nullable', 'array'], 'allowed_ips.*' => ['required', 'ip'], ]; ``` However, you want to make sure the current user's current IP address is included in the provided array of input. Current rules do not provide a way to do this. With the new `has` rule, the rules would change to: ```php return [ 'allowed_ips' => ['present', 'nullable', 'array', 'has:' . $request->ip()], 'allowed_ips.*' => ['required', 'ip'], ]; ``` You may also pass multiple parameters to the `has` rule, which would require all of the passed parameters to exist in the given input. * minor styling * formatting --------- Co-authored-by: Taylor Otwell <[email protected]>
- Loading branch information