Skip to content

Instantly share code, notes, and snippets.

@arondeparon
Created July 14, 2016 08:22
Show Gist options
  • 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