-
Notifications
You must be signed in to change notification settings - Fork 26
Defining Column Validator
Yo-An Lin edited this page May 7, 2017
·
3 revisions
The prototype of Column::validator method:
Column::validator(string functionName | Closure | Validator Name provided from ValidationKit)
To define a validator for a column in the schema, you may pass a Closure to customize your validation logics:
$this->column('address')
->varchar(64)
->validator(function ($val, $args) {
if (strlen($val) < 6) {
return [false , "The given address is not clear enough"];
}
return [true , "Good address"];
})The closure used for validating value should return a 2 element array as the result, the first element needs to be a boolean value, true means the validation succeed, false means the validation failed, the second element needs to be a string, it presents the reason describing why the validation failed or succeed.