-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[5.6] Adds new comparison validation rules to compare two fields against each other. #23807
Conversation
Nice. If this PR gets accepted @Alymosul - can you please do a PR on the Laravel Docs to document this new validation option. |
Sure! Just waiting for Taylor’s decision. |
@Alymosul also the translations for the laravel/laravel repository. |
* @param $first | ||
* @param $second | ||
*/ | ||
protected function requireSameTypeValues($first, $second) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing @return
and @throws
Compared to all existing validation rules, the naming suggests you could indeed do the following: $rules = [
'salary' => 'greater_than:36000',
'fees' => 'less_than:3500'
]; I understand there's 'min' and 'max', but this will be a major source of confusion in the future. IMO we need to back up and try again. I like the idea, but not the implementation or naming. Personally, I think a custom rule in your project or a small package with similar functionality would be the best place for this. |
what's wrong with the implementation? |
Forgive me. After re-reading, the actual implementation seems fine. |
I agree it may be beneficial to allow specifying an integer number the field must be greater than. Also, what about the eventual "can we have greater than or equal to?" |
I think we can have greater than or equal as a separate validation rule, but i think if we will allow specifying an integer number then it overlaps with the 'max' rule, the concept behind this rule is the comparison against another field... so what do you think about that? |
Feel free to submit when it can take integers and handles "equal to"... personally I would just shorten the rules to something like |
This PR adds two new validation rules
greater_than
&less_than
, those two new rules will be used to compare two fields against each other, the two rules are different thanmax/min
rules because the two fields under validation must be of the same type also they passed parameter cannot be a hard coded value..An example:
Supposedly we have a form that takes two input min_salary & max_salary...
The above rules will enforce the min_salary to respect the max_salary value and vice versa.