Closed willemo closed 7 years ago
Can you describe a use case for this?
Sure! I'm using it for manual or stored filters when doing a GET request to my API:
You can either make this request: GET /endpoint?foo=bar&baz=123
Or make this request: GET /endpoint?filter_id=321
If you'd do both in the same request, the validator would fail.
You can set it up like so:
$validator = Validator::make($request->all(), [
'foo' => 'string|nullable|empty_with:filter_id',
'baz' => 'integer|nullable|empty_with:filter_id',
'filter_id' => 'integer|nullable|exists:filters,id',
]);
The filter_id
field doesn't need an empty_with
validator, since that's being covered by the other fields having it.
Sounds good.
I've added an empty_with validator that checks if either the field under validation is empty or all of the other specified fields. With this validator you can make an
either [this field] or [that field]
validation.