Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 29, 2019 21:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/a3784dfdc2753320444c5122788f68a9 to your computer and use it in GitHub Desktop.
Save parzibyte/a3784dfdc2753320444c5122788f68a9 to your computer and use it in GitHub Desktop.
<?php
namespace Parzibyte;
class Validator
{
public static function validateOrRedirect($data, $rules, $route = null)
{
$validator = new \Valitron\Validator($data);
$validator->rules($rules);
if (!$validator->validate()) {
$redirect = Redirect::with([
"errores_formulario" => $validator->errors(),
]);
if ($route != null) {
$redirect->to($route);
} else {
$redirect->back();
}
$redirect->do();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment