Created
April 7, 2017 13:57
-
-
Save gustavonovaes/8cfb7ad777d4588db1d435dc674e8f48 to your computer and use it in GitHub Desktop.
Helper para o vlucas/valitron
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function validate(array $data, array $rules) | |
{ | |
$v = new Valitron\Validator($data); | |
foreach ($rules as $rule => $fields) { | |
$optional = null; | |
$rule = explode('=', $rule); | |
if (count($rule) > 1) { | |
$optional = $rule[1]; | |
} | |
$rule = $rule[0]; | |
if ($optional !== null) { | |
$v->rule($rule, $fields, $optional); | |
continue; | |
} | |
$v->rule($rule, $fields); | |
} | |
if (!$v->validate()) { | |
return $v->errors(); | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment