@@ -140,9 +140,10 @@ Before register/set custom messages, here are some variables you can use in your
140
140
141
141
* ` :attribute ` : will replaced into attribute alias.
142
142
* ` :value ` : will replaced into stringify value of attribute. For array and object will replaced to json.
143
- * ` :params[n] ` : will replaced into rule parameter, ` n ` is index array. For example ` :params[0] ` in ` min:6 ` will replaced into ` 6 ` .
144
143
145
- And here are some ways to register/set your custom message(s):
144
+ And also there are several message variables depends on their rules.
145
+
146
+ Here are some ways to register/set your custom message(s):
146
147
147
148
#### Custom Messages for Validator
148
149
@@ -305,7 +306,7 @@ For uploaded file, `$_FILES['key']['error']` must not `UPLOAD_ERR_NO_FILE`.
305
306
306
307
The field under this rule must be present and not empty if the anotherfield field is equal to any value.
307
308
308
- For example ` required_if:something,1,yes,on ` will be required if ` something ` value is one of ` 1 ` , ` '1' ` , ` 'yes' ` , or ` 'on' ` .
309
+ For example ` required_if:something,1,yes,on ` will be required if ` something ` value is one of ` 1 ` , ` '1' ` , ` 'yes' ` , or ` 'on' ` .
309
310
310
311
<a id =" rule-uploaded_file " ></a >
311
312
#### uploaded_file: min_size ,max_size,file_type_a,file_type_b,...
@@ -353,12 +354,12 @@ The field under this rule must be entirely alpha-numeric characters.
353
354
The field under this rule may have alpha-numeric characters, as well as dashes and underscores.
354
355
355
356
<a id =" rule-in " ></a >
356
- #### in
357
+ #### in: value_1 ,value_2,...
357
358
358
359
The field under this rule must be included in the given list of values.
359
360
360
361
<a id =" rule-not_in " ></a >
361
- #### not_in
362
+ #### not_in: value_1 ,value_2,...
362
363
363
364
The field under this rule must not be included in the given list of values.
364
365
@@ -504,21 +505,22 @@ class UniqueRule extends Rule
504
505
505
506
```
506
507
507
- Then you can register ` UniqueRule ` instance into validator like this:
508
+ Then you need to register ` UniqueRule ` instance into validator like this:
508
509
509
510
``` php
510
511
use Rakit\Validation\Validator;
511
512
512
513
$validator = new Validator;
513
514
514
- // register it
515
515
$validator->addValidator('unique', new UniqueRule($pdo));
516
+ ```
517
+
518
+ Now you can use it like this:
516
519
517
- // then you can use it like this:
520
+ ``` php
518
521
$validation = $validator->validate($_POST, [
519
- 'email' => '
required| email|unique:users,email,
[email protected] '
522
+ 'email' => 'email|unique:users,email,
[email protected] '
520
523
]);
521
-
522
524
```
523
525
524
526
In
` UniqueRule ` above, property
` $message ` is used for default invalid message. And property
` $fillable_params ` is used for
` setParameters ` method (defined in
` Rakit\Validation\Rule ` class). By default
` setParameters ` will fill parameters listed in
` $fillable_params ` . For example
` unique:users,email,[email protected] ` in example above, will set:
@@ -529,7 +531,8 @@ $params['column'] = 'email';
529
531
$params['except'] = '
[email protected] ';
530
532
```
531
533
532
- So if you want your own rule have dynamic rule params, you just need to override ` setParameters(array $params) ` method in your own Rule class.
534
+ > If you want your custom rule accept parameter list like ` in ` ,` not_in ` , or ` uploaded_file ` rules,
535
+ you just need to override ` setParameters(array $params) ` method in your custom rule class.
533
536
534
537
Note that ` unique ` rule that we created above also can be used like this:
535
538
@@ -561,7 +564,7 @@ class UniqueRule extends Rule
561
564
562
565
public function column($column)
563
566
{
564
- $this->params['table '] = $column;
567
+ $this->params['column '] = $column;
565
568
return $this;
566
569
}
567
570
@@ -576,7 +579,7 @@ class UniqueRule extends Rule
576
579
577
580
```
578
581
579
- And then you can use it in more funky way like this:
582
+ Then you can use it in more funky way like this:
580
583
581
584
``` php
582
585
$validation = $validator->validate($_POST, [
0 commit comments