Fluent Numeric Validation and Conditional Prohibition Rules in Laravel
laravel
release
validation

Nabil Hassen
•
Feb 20, 2025

Last updated on Feb 20, 2025
Table of contents:
Fluent Numeric Validation
@xoesae introduced a new Numeric
class for defining numeric validation rules in a more structured way. Previously, validation rules were defined as strings:
$rules = [ 'score' => 'numeric|integer|multiple_of:10|lte:some_field|max:100',];
Now, they can be written fluently:
use Illuminate\Validation\Rules\Numeric; $rules = [ 'score' => [ Numeric::make() ->integer() ->multipleOf(10) ->lte('some_field') ->max(100), ],];
More details in PR #54425.
Conditional Prohibition Rules
@osama-98 added two new validation rules: prohibited_if_accepted
and prohibited_if_declined
. These rules prevent a field from being included when another field is accepted or declined.
For example, to prohibit the reason
field if terms
is accepted:
$rules = [ 'terms' => 'accepted', 'reason' => 'prohibited_if_accepted:terms',];
To prohibit reason
if terms
is declined:
$rules = [ 'terms' => 'declined', 'reason' => 'prohibited_if_declined:terms',];
More details in PR #54608.
Stay Updated.
I'll you email you as soon as new, fresh content is published.
Thanks for subscribing to my blog.
Latest Posts