Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit e705a79

Browse files
committed
feat: added GreaterThan rule documentation
1 parent 498f1a9 commit e705a79

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

docs/03-rules-greater-than.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# GreaterThan
2+
3+
Validates that a value is greater than another value. Can compare between strings, numbers and dates.
4+
5+
## Basic Usage
6+
7+
```php
8+
Validator::greaterThan(10)->validate(20); // true
9+
Validator::greaterThan(1.5)->validate(2.5); // true
10+
Validator::greaterThan('alpha')->validate('beta'); // true
11+
Validator::greaterThan(new DateTime('today'))->validate(new DateTime('tomorrow')); // true
12+
```
13+
14+
> **Note**
15+
> String comparison is case-sensitive, meaning that comparing `'hello'` with `'Hello'` is different.
16+
> Check [`strcmp`](https://www.php.net/manual/en/function.strcmp.php) for more information.
17+
18+
> **Note**
19+
> An `UnexpectedValueException` will be thrown when trying to compare incomparable values, like a `string` with an `int`.
20+
21+
## Options
22+
23+
### `constraint`
24+
25+
type: `mixed` `required`
26+
27+
It defines the comparison/minimum value. Can be a string, number or `DateTimeInterface` object.
28+
29+
### `message`
30+
31+
type: `string` default: `The "{{ name }}" value should be greater than "{{ constraint }}", "{{ value }}" given.`
32+
33+
Message that will be shown if the value is not greater than the constraint value. Check the [Custom Messages]() section for more information.
34+
35+
The following parameters are available:
36+
37+
| Parameter | Description |
38+
|--------------------|------------------------------------|
39+
| `{{ value }}` | The current invalid value |
40+
| `{{ name }}` | Name of the value being validated |
41+
| `{{ constraint }}` | The comparison/minimum value |

0 commit comments

Comments
 (0)