LessThanRule extends ComparisonRule
Validation rule that ensures a given value is **less than** another field's value or to a fixed numeric constant.
This rule can be used to enforce constraints between numeric fields (e.g. durations, limits, quotas) or to validate a value against a fixed threshold.
Usage examples
// Compare with another field
$validation = $validator->validate($data,
[
'implicitHybridTokenLifetime' => 'lt_field:maximumAccessTokenExpiration',
]);
// Compare with a fixed value
$validation = $validator->validate($data,
[
'timeout' => 'lt_field:3600',
]);
When validation fails, the default message is:
The :attribute must be less than :comparison_field.
Tags
Table of Contents
Constants
- COMPARISON_FIELD = 'comparison_field'
- The 'comparison_field' parameter.
Properties
- $fillableParams : array<string|int, mixed>
- $message : string
Methods
- check() : bool
- Performs the comparison between the attribute value and the comparison value.
- compare() : bool
- Must be implemented by subclasses to perform the actual comparison.
- getComparisonValue() : mixed
- Get the comparison value from either a field name or a direct value
Constants
COMPARISON_FIELD
The 'comparison_field' parameter.
public
mixed
COMPARISON_FIELD
= 'comparison_field'
Properties
$fillableParams
protected
array<string|int, mixed>
$fillableParams
= [self::COMPARISON_FIELD]
$message
protected
string
$message
= 'The :attribute must be less than :comparison_field.'
Methods
check()
Performs the comparison between the attribute value and the comparison value.
public
check(mixed $value) : bool
Parameters
- $value : mixed
-
The value of the current attribute being validated.
Tags
Return values
bool —True if the comparison succeeds, false otherwise.
compare()
Must be implemented by subclasses to perform the actual comparison.
protected
compare(float|int $a, float|int $b) : bool
Parameters
- $a : float|int
-
The attribute value.
- $b : float|int
-
The comparison value.
Return values
bool —True if the rule condition is met.
getComparisonValue()
Get the comparison value from either a field name or a direct value
protected
getComparisonValue(string $fieldOrValue) : mixed
Parameters
- $fieldOrValue : string