Created
July 14, 2016 08:22
-
-
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
This file contains hidden or 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
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