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

Open
wants to merge 2 commits into
base: 11.x
Choose a base branch
from

Conversation

xoesae
Copy link

@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();
}

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.

1 participant