Skip to content

Commit e9d602f

Browse files
authored
Update readme
1 parent 8a6295c commit e9d602f

File tree

1 file changed

+16
-13
lines changed

1 file changed

+16
-13
lines changed

README.md

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,10 @@ Before register/set custom messages, here are some variables you can use in your
140140

141141
* `:attribute`: will replaced into attribute alias.
142142
* `: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`.
144143

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):
146147

147148
#### Custom Messages for Validator
148149

@@ -305,7 +306,7 @@ For uploaded file, `$_FILES['key']['error']` must not `UPLOAD_ERR_NO_FILE`.
305306

306307
The field under this rule must be present and not empty if the anotherfield field is equal to any value.
307308

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'`.
309310

310311
<a id="rule-uploaded_file"></a>
311312
#### 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.
353354
The field under this rule may have alpha-numeric characters, as well as dashes and underscores.
354355

355356
<a id="rule-in"></a>
356-
#### in
357+
#### in:value_1,value_2,...
357358

358359
The field under this rule must be included in the given list of values.
359360

360361
<a id="rule-not_in"></a>
361-
#### not_in
362+
#### not_in:value_1,value_2,...
362363

363364
The field under this rule must not be included in the given list of values.
364365

@@ -504,21 +505,22 @@ class UniqueRule extends Rule
504505

505506
```
506507

507-
Then you can register `UniqueRule` instance into validator like this:
508+
Then you need to register `UniqueRule` instance into validator like this:
508509

509510
```php
510511
use Rakit\Validation\Validator;
511512

512513
$validator = new Validator;
513514

514-
// register it
515515
$validator->addValidator('unique', new UniqueRule($pdo));
516+
```
517+
518+
Now you can use it like this:
516519

517-
// then you can use it like this:
520+
```php
518521
$validation = $validator->validate($_POST, [
519-
'email' => 'required|email|unique:users,email,[email protected]'
522+
'email' => 'email|unique:users,email,[email protected]'
520523
]);
521-
522524
```
523525

524526
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';
529531
$params['except'] = '[email protected]';
530532
```
531533

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.
533536

534537
Note that `unique` rule that we created above also can be used like this:
535538

@@ -561,7 +564,7 @@ class UniqueRule extends Rule
561564

562565
public function column($column)
563566
{
564-
$this->params['table'] = $column;
567+
$this->params['column'] = $column;
565568
return $this;
566569
}
567570

@@ -576,7 +579,7 @@ class UniqueRule extends Rule
576579

577580
```
578581

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:
580583

581584
```php
582585
$validation = $validator->validate($_POST, [

0 commit comments

Comments
 (0)