mirror of
https://github.com/Respect/Validation.git
synced 2024-05-02 14:42:47 +02:00
Updated documentation about custom rules
The documentation about custom rules does not specify that creating an exception for the rule is necessary. This commit will add that to the documentation with an example to make it explicit. Co-authored-by: Henrique Moody <henriquemoody@gmail.com>
This commit is contained in:
parent
66f5475463
commit
780233a44b
|
@ -260,6 +260,30 @@ v::with('My\\Validation\\Rules', true);
|
|||
v::alnum(); // Try to use "My\Validation\Rules\Alnum" if any
|
||||
```
|
||||
|
||||
If you're using the `assert()` or `check()` methods you also need to create an
|
||||
Exception to declare the messages returned:
|
||||
|
||||
```php
|
||||
namespace My\Validation\Exceptions;
|
||||
|
||||
use Respect\Validation\Exceptions\ValidationException;
|
||||
|
||||
class MyRuleException extends ValidationException
|
||||
{
|
||||
public static $defaultTemplates = [
|
||||
self::MODE_DEFAULT => [
|
||||
self::STANDARD => '{{name}} must pass my rules',
|
||||
],
|
||||
self::MODE_NEGATIVE => [
|
||||
self::STANDARD => '{{name}} must not pass my rules',
|
||||
]
|
||||
];
|
||||
}
|
||||
```
|
||||
|
||||
Notice that while the namespace of the rule is `My\Validation\Rules` the
|
||||
namespace of the exception is `My\Validation\Exceptions`.
|
||||
|
||||
## Validator name
|
||||
|
||||
On `v::attribute()` and `v::key()`, `{{name}}` is the attribute/key name. For others,
|
||||
|
|
Loading…
Reference in a new issue