Skip to content

Instantly share code, notes, and snippets.

@gustavonovaes
Created April 7, 2017 13:57
Show Gist options
  • Save gustavonovaes/8cfb7ad777d4588db1d435dc674e8f48 to your computer and use it in GitHub Desktop.
Save gustavonovaes/8cfb7ad777d4588db1d435dc674e8f48 to your computer and use it in GitHub Desktop.
Helper para o vlucas/valitron
<?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