Skip to content
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

[11.x] Fluent numeric validation #54425

Merged
merged 3 commits into from
Feb 5, 2025

Conversation

xoesae
Copy link
Contributor

@xoesae xoesae commented Jan 31, 2025

Description

This pull request introduces a new fluent numeric validation class, offering a more elegant and expressive way to define numeric validation rules.

Before this PR, numeric validation required string-based rules:

$rules = [
    'score' => 'numeric|integer|multiple_of:10|lte:some_field|max:100',
];

$validator = Validator::make($data, $rules);

if ($validator->fails()) {
    return $validator->errors();
}

To use the fluent numeric validation:

use Illuminate\Validation\Rule;

$rules = [
    'score' => [
        Rule::numeric()
            ->integer()
            ->multipleOf(10)
            ->lessThanOrEqual('some_field')
            ->max(100);
    ],
];

$validator = Validator::make($data, $rules);

if ($validator->fails()) {
    return $validator->errors();
}

@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

@taylorotwell taylorotwell reopened this Feb 5, 2025
@taylorotwell taylorotwell merged commit 75b6392 into laravel:11.x Feb 5, 2025
16 of 38 checks passed
crynobone added a commit that referenced this pull request Feb 5, 2025
fixes tests failure introduced in #54425

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
@crynobone crynobone mentioned this pull request Feb 5, 2025
taylorotwell pushed a commit that referenced this pull request Feb 5, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
* Test Improvements

fixes tests failure introduced in #54425

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

* wip

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>

---------

Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
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

Successfully merging this pull request may close these issues.

None yet

2 participants