Fluent Numeric Validation in Laravel

Fluent Numeric Validation in Laravel

Numeric validation in Laravel gets more intuitive with a new fluent interface that transforms verbose rule strings into chainable methods.

Laravel's Rule::numeric() method provides a cleaner way to build complex numeric validation rules. Instead of stringing together pipe-delimited constraints, you can now chain methods in a readable, IDE-friendly format.

// Before
$rules = [
    'price' => 'numeric|min:5|max:1000|decimal:2',
];

// After
$rules = [
    'price' => Rule::numeric()
        ->min(5)
        ->max(1000)
        ->decimal(2),
];

The fluent interface supports all numeric validation features while making your rules more maintainable. Whether you're validating integers, decimal places, or relative values, the new syntax keeps your validation logic clean and explicit.

If this guide was helpful to you, subscribe to my daily newsletter and give me a follow on X/Twitter and Bluesky. It helps a lot!

Subscribe to Harris Raftopoulos

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe