Created
November 30, 2015 21:38
-
-
Save cviebrock/bab707a338cb03ec19de to your computer and use it in GitHub Desktop.
Validate a list of things
This file contains 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
<?php | |
namespace App\Validators; | |
use Illuminate\Contracts\Validation\Validator; | |
class ListOfValidator | |
{ | |
public function validate($attribute, $value, $parameters, Validator $validator) | |
{ | |
// extract all the values | |
$values = explode(',', $value); | |
// reconstitute the parameters | |
$newRules = join('|', $parameters); | |
// revalidate each value | |
foreach ($values as $newValue) { | |
$newValidator = \Validator::make( | |
['value' => $newValue], | |
['value' => $newRules] | |
); | |
if ($newValidator->fails()) { | |
return false; | |
}; | |
} | |
return true; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment