|
| 1 | +# Blank |
| 2 | + |
| 3 | +Validates that a value is equal to an empty string, empty array, `false` or `null`. |
| 4 | + |
| 5 | +Check the [NotBlank](03-rules_not-blank.md) rule for the opposite validation. |
| 6 | + |
| 7 | +```php |
| 8 | +Blank( |
| 9 | + ?callable $normalizer = null, |
| 10 | + ?string $message = null |
| 11 | +); |
| 12 | +``` |
| 13 | + |
| 14 | +## Basic Usage |
| 15 | + |
| 16 | +Bellow are the *only* cases where the rule will succeed by default, |
| 17 | +everything else is considered invalid (you may want to check the [`normalizer`](#normalizer) option for a different behaviour): |
| 18 | + |
| 19 | +```php |
| 20 | +Validator::blank()->validate(''); // true |
| 21 | +Validator::blank()->validate([]); // true |
| 22 | +Validator::blank()->validate(false); // true |
| 23 | +Validator::blank()->validate(null); // true |
| 24 | +``` |
| 25 | + |
| 26 | +## Options |
| 27 | + |
| 28 | +### `normalizer` |
| 29 | + |
| 30 | +type: `?callable` default: `null` |
| 31 | + |
| 32 | +Allows to define a `callable` that will be applied to the value before checking if it is valid. |
| 33 | + |
| 34 | +For example, use `trim`, or pass your own function, to allow a string with whitespaces only: |
| 35 | + |
| 36 | +```php |
| 37 | +Validator::blank(normalizer: 'trim')->validate(' '); // true |
| 38 | +Validator::blank(normalizer: fn($value) => trim($value))->validate(' '); // true |
| 39 | +``` |
| 40 | + |
| 41 | +### `message` |
| 42 | + |
| 43 | +type: `?string` default: `The {{ name }} value should be blank, {{ value }} given.` |
| 44 | + |
| 45 | +Message that will be shown if the value is not blank. |
| 46 | + |
| 47 | +The following parameters are available: |
| 48 | + |
| 49 | +| Parameter | Description | |
| 50 | +|---------------|---------------------------| |
| 51 | +| `{{ value }}` | The current invalid value | |
| 52 | +| `{{ name }}` | Name of the invalid value | |
| 53 | + |
| 54 | +## Changelog |
| 55 | + |
| 56 | +- `1.2.0` Created |
0 commit comments