Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Validator::validate() and Validator::valid() not returning the same output #55730

Copy link
Copy link
Closed
@bluesheep100

Description

@bluesheep100
Issue body actions

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.