Skip to content

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 <[email protected]>
@crynobone crynobone mentioned this pull request Feb 5, 2025
taylorotwell pushed a commit that referenced this pull request Feb 5, 2025
* Test Improvements

fixes tests failure introduced in #54425

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
@siarheipashkevich
Copy link
Contributor

@xoesae what about the strict type?
https://laravel.com/docs/12.x/validation#rule-numeric

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.

3 participants