Skip to content

Commit 3f5650a

Browse files
committed
Update readme
1 parent 31508dc commit 3f5650a

File tree

1 file changed

+25
-19
lines changed

1 file changed

+25
-19
lines changed

README.md

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -38,27 +38,30 @@ use Rakit\Validation\Validator;
3838
$validator = new Validator;
3939

4040
// make it
41-
$validation = $validator->make($_POST, [
42-
'name' => 'required',
43-
'email' => 'required|email',
44-
'password' => 'required|min:6',
41+
$validation = $validator->make($_POST + $_FILES, [
42+
'name' => 'required',
43+
'email' => 'required|email',
44+
'password' => 'required|min:6',
4545
'confirm_password' => 'required|same:password',
46-
'avatar' => 'required|uploaded_file:0,500K,png,jpeg',
46+
'avatar' => 'required|uploaded_file:0,500K,png,jpeg',
47+
'skills' => 'array',
48+
'skills.*.id' => 'required|numeric',
49+
'skills.*.percentage' => 'required|numeric'
4750
]);
4851

4952
// then validate
5053
$validation->validate();
5154

5255
if ($validation->fails()) {
53-
// handling errors
54-
$errors = $validation->errors();
55-
echo "<pre>";
56-
print_r($errors->firstOfAll());
57-
echo "</pre>";
58-
exit;
56+
// handling errors
57+
$errors = $validation->errors();
58+
echo "<pre>";
59+
print_r($errors->firstOfAll());
60+
echo "</pre>";
61+
exit;
5962
} else {
60-
// validation passes
61-
echo "Success!";
63+
// validation passes
64+
echo "Success!";
6265
}
6366

6467
```
@@ -74,12 +77,15 @@ use Rakit\Validation\Validator;
7477

7578
$validator = new Validator;
7679

77-
$validation = $validator->validate($_POST, [
78-
'name' => 'required',
79-
'email' => 'required|email',
80-
'password' => 'required|min:6',
80+
$validation = $validator->validate($_POST + $_FILES, [
81+
'name' => 'required',
82+
'email' => 'required|email',
83+
'password' => 'required|min:6',
8184
'confirm_password' => 'required|same:password',
82-
'avatar' => 'required|uploaded_file:0,500K,png,jpeg',
85+
'avatar' => 'required|uploaded_file:0,500K,png,jpeg',
86+
'skills' => 'array',
87+
'skills.*.id' => 'required|numeric',
88+
'skills.*.percentage' => 'required|numeric'
8389
]);
8490

8591
if ($validation->fails()) {
@@ -96,7 +102,7 @@ if ($validation->fails()) {
96102

97103
```
98104

99-
In this case, 2 example above will output the same results.
105+
In this case, 2 examples above will output the same results.
100106

101107
But with `make` you can setup something like custom invalid message, custom attribute alias, etc before validation running.
102108

0 commit comments

Comments
 (0)