You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Implicit rule is a rule that if it's invalid, then next rules will be ignored.
987
+
For example `required*` rules, if some attribute didn't pass `required*` rules, it's next rules will also be invalids. So to prevent our next rules messages to get collected, we make `required*` rules to be implicit.
988
+
989
+
To make your custom rule implicit, you can make `$implicit` property value to be `true`. For example:
990
+
991
+
```php
992
+
<?php
993
+
994
+
use Rakit\Validation\Rule;
995
+
996
+
class YourCustomRule extends Rule
997
+
{
998
+
999
+
protected $implicit = true;
1000
+
1001
+
}
1002
+
```
1003
+
1004
+
#### Modify Value
1005
+
1006
+
In some case, you may want your custom rule to be able to modify it's attribute value like our `default/defaults` rule. So in current and next rules checks, your modified value will be used.
1007
+
1008
+
To do this, you should implements `Rakit\Validation\Rules\Interfaces\ModifyValue` and create method `modifyValue($value)` to your custom rule class.
1009
+
1010
+
For example:
1011
+
1012
+
```php
1013
+
<?php
1014
+
1015
+
use Rakit\Validation\Rule;
1016
+
use Rakit\Validation\Rules\Interfaces\ModifyValue;
1017
+
1018
+
class YourCustomRule extends Rule implements ModifyValue
1019
+
{
1020
+
...
1021
+
1022
+
public function modifyValue($value)
1023
+
{
1024
+
// Do something with $value
1025
+
1026
+
return $value;
1027
+
}
1028
+
1029
+
...
1030
+
}
1031
+
```
1032
+
1033
+
#### Before Validation Hook
1034
+
1035
+
You may want to do some preparation before validation running. For example our `uploaded_file` rule will resolves attribute value that come from `$_FILES` (undesirable) array structure to be well-organized array structure, so we can validate multiple file upload just like validating other data.
1036
+
1037
+
To do this, you should implements `Rakit\Validation\Rules\Interfaces\BeforeValidate` and create method `beforeValidate()` to your custom rule class.
1038
+
1039
+
For example:
1040
+
1041
+
```php
1042
+
<?php
1043
+
1044
+
use Rakit\Validation\Rule;
1045
+
use Rakit\Validation\Rules\Interfaces\BeforeValidate;
1046
+
1047
+
class YourCustomRule extends Rule implements BeforeValidate
0 commit comments