Skip to content

Instantly share code, notes, and snippets.

@ArondeParon
Created July 14, 2016 08:22
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 ArondeParon/21cfe8eb5724842f9f1d3bae9f08d8c9 to your computer and use it in GitHub Desktop.
Save ArondeParon/21cfe8eb5724842f9f1d3bae9f08d8c9 to your computer and use it in GitHub Desktop.
Laraval Custom Validator to validate that at least one item in an array is filled
Validator::extend('at_least_one_filled', function($attribute, $value, $parameters, $validator) {
if (is_array($value)) {
$filteredArray = array_filter($value);
return count($filteredArray) > 0;
} else {
return !empty($value);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment