Skip to content

Commit 226a18b

Browse files
Update README.md
1 parent 221cad9 commit 226a18b

1 file changed

Lines changed: 12 additions & 30 deletions

File tree

README.md

Lines changed: 12 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -306,11 +306,11 @@ $errors = $validator->errors();
306306
| not_in | array | match data in given array. |
307307
| equal | mixed | it will match data with given data. |
308308
| not_equal | mixed | it will match data with given data. |
309-
| rules | array | set custom validation rules. custom rules are set of key value pairs, if any key has false value then it will throw an error. we can pass callback function in custom validation rules. function accept one parameter `value` and return true or false values. |
310309

311310
### Set Custom Rules
312311

313312
We can set predefined/custom rules for data validation.
313+
if custom rule return `true` that means data is valid and if it will return `false` that means data is invalid.
314314

315315
```php
316316
// Set validation rules
@@ -320,39 +320,21 @@ $validator = Validator::make([
320320
'not_null' => true,
321321
'string' => true
322322
],
323-
'gender' => [
324-
'required' => true,
325-
'not_null' => true,
326-
'string' => true,
327-
'in' => ['male', 'female', 'other']
328-
],
329323
'email' => [
330324
'required' => true,
331325
'not_null' => true,
332326
'email' => true,
333-
'rules' => [
334-
// Set your own custom rules
335-
'blocked' => function($value) {
336-
if($value == 'abc@gmail.com') {
337-
// Email abc@gmail.com is blocked
338-
return false;
339-
} else {
340-
return true;
341-
}
342-
},
343-
'available' => is_available($value)
344-
]
345-
],
346-
'password' => [
347-
'required' => true,
348-
'not_null' => true,
349-
'minlength' => 6,
350-
'maxlength' => 15
351-
],
352-
'profile_image' => [
353-
'file' => true,
354-
'max_file_size' => 2000000,
355-
'file_extension' => ['jpg', 'png']
327+
// Set your own custom rules
328+
'blocked' => function($value) {
329+
if($value == 'abc@gmail.com') {
330+
// Email abc@gmail.com is blocked
331+
return false;
332+
} else {
333+
return true;
334+
}
335+
},
336+
// Set your own custom rules
337+
'available' => is_available($value),
356338
]
357339
]);
358340
```

0 commit comments

Comments
 (0)