8000 Validator::validate() and Validator::valid() not returning the same output · Issue #55730 · laravel/framework · GitHub
[go: up one dir, main page]

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
bluesheep100 opened this issue May 14, 2025 · 2 comments
Closed

Comments

@bluesheep100
Copy link

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']
@crynobone
Copy link
Member

Hi there,

Thanks for reporting the problem you are encountering, but it looks like this is a question which may be better suited for a support channel. We only use this issue tracker for reporting bugs with the library itself. If you have a question on how to use functionality provided by this repository you can try one of the following channels:

However, this issue will not be locked and everyone is still free to discuss solutions to your problem!

Thanks.

@bluesheep100
Copy link
Author

I posted this here, because I believe this to be a bug in my own eyes, but I'm open to a statement from the Laravel team stating it's an intentional feature. Just feels really unintuitive/potentially unsafe to me, that these methods behave differently like this.
If it's intentional, I'll just go open a PR to add it to the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0