Closed
Description
Laravel Version
12.12.0
PHP Version
8.4.7, Zend Engine 4.4.7
Database Driver & Version
No response
Description
Validator::validate()
and Validator::valid()
do not return the same list of valid data.
Validator::validate()
returns only the data that has passed a validation rule.
Validator::valid()
ALL data that did not explicitly fail a validation rule.
This may be an intentional feature, but maybe we ought to have this distinction in the docs somewhere, or a feature that lets you toggle this behaviour? The main use case is auto save, where you'd wanna only update/save whatever is currently validated.
Steps To Reproduce
Create two validators with the same data and rules, and call the two methods on them:
$data = ['foo' => 'bar', 'buzz' => 'foobar'];
$rules = ['foo' => 'required|in:bar,baz'];
dd(
\Validator::make($data, $rules)->validate(),
\Validator::make($data, $rules)->valid(),
);
// ['foo' => 'bar']
// ['foo' => 'bar', 'buzz' => 'foobar']
Metadata
Metadata
Assignees
Labels
No labels