{"id":20525996,"url":"https://github.com/codeyellowbv/validator","last_synced_at":"2026-04-15T20:32:05.872Z","repository":{"id":66356478,"uuid":"75202484","full_name":"CodeYellowBV/validator","owner":"CodeYellowBV","description":"An extension of the laravel Validator","archived":false,"fork":false,"pushed_at":"2016-11-30T15:57:05.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":9,"default_branch":"master","last_synced_at":"2025-03-06T01:45:39.400Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/CodeYellowBV.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-11-30T15:55:35.000Z","updated_at":"2016-11-30T15:55:55.000Z","dependencies_parsed_at":"2023-02-22T06:30:54.370Z","dependency_job_id":null,"html_url":"https://github.com/CodeYellowBV/validator","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/CodeYellowBV/validator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeYellowBV%2Fvalidator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeYellowBV%2Fvalidator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeYellowBV%2Fvalidator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeYellowBV%2Fvalidator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CodeYellowBV","download_url":"https://codeload.github.com/CodeYellowBV/validator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CodeYellowBV%2Fvalidator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31859276,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-15T15:24:51.572Z","status":"ssl_error","status_checked_at":"2026-04-15T15:24:39.138Z","response_time":63,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-15T23:11:46.352Z","updated_at":"2026-04-15T20:32:05.856Z","avatar_url":"https://github.com/CodeYellowBV.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Readme\n\nCodeYellow/Validation is an extension for Illuminate/Validation - the validation library of Laravel 5. It eliminates the necessity to create validators using\nthe factory methods, and instead lets you define the validator as a stand alone class. This allows for easy extension of the validation class, makes code reuse simpler,\nand seperates the responsibility of validation logic from the model and service. Furthermore CodeYellow/Validation gives adds a lot of usefull features to make validation\neven simpler.\n\n## Defining a validator\nDefining a validator is very easy. Create a class that extends the ```\\CodeYellow\\Validation\\Validator``` class, and create a variable $rules with the same validation rules\nas you can use in Illuminate/Validation. For example:\n\n\n```php\n\u003c?php\nclass SimpleValidator extends \\CodeYellow\\Validation\\Validator\n{\n    protected $rules = [\n        'age' =\u003e 'required|numeric|min:5',\n        'size' =\u003e 'numeric|min:10'\n    ];\n}\n```\n\nYour rules do not have to be static. If the rules depend on some kind of variable, a method getRules can be defined to return a dynamic definition of rules. For example;\n\n```php\n\u003c?php\nclass MoreAdvancedValidator extends \\CodeYellow\\Validation\\Validator\n{\n    protected $minAge = 5;\n\n    public function setMinAge($age) {\n        $this-\u003eminAge = $age;\n    }\n\n\n    public function getRules() {\n        return [\n                   'age' =\u003e 'required|numeric|min:' . $minAge,\n                   'size' =\u003e 'numeric|min:10'\n               ];\n    }\n}\n```\n\n\n## Using a validator\n\nValidators can be injected through normal dependency injection, and has got two methods. The verify method returns a boolean that indicates if\nthe data satisfies the validator. The parse method throws a \\Illuminate\\Validation\\ValidationException if the data does not validate. If the data does validate\nthe data is parsed in the correct format. See the following example:\n\n```php\n\u003c?php\n$goodData = [\n    'age' =\u003e '7',\n    'size' =\u003e '12'\n];\n\n$badData = [\n    'age' =\u003e '3',\n    'size' =\u003e '11'\n];\n\n$simpleValidator = app()-\u003emake('SimpleValidator'); // Create the simplevalidator as defined above\n\n$simpleValidator-\u003evalidate($goodData); // True\n$goodData; //  ['age' =\u003e '7', 'size' =\u003e '12' ];\n$simpleValidator-\u003evalidate($badData); // false\n\n\n$simpleValidator-\u003eparse($goodData); // ['age' =\u003e 7, 'size' =\u003e 12 ];\n$goodData; // ['age' =\u003e 7, 'size' =\u003e 12 ];\n$simpleValidator-\u003eparse($badData); // ValidationException\n\n```\n\n## Extending a validator\n\nYou can add methods to the validator by naming them \"validateStuff\" that returns a boolean, where stuff is the name of your validation. For example, see the following validator which checks if\na number is even. See the Laravel documentation for how you can define custom error messages for your validation\n\n```php\n\u003c?php\nclass IsEvenValidator extends \\CodeYellow\\Validation\\Validator\n{\n    protected $rules = [\n        'age' =\u003e 'required|even',\n    ];\n\n    public function validateEven($number) {\n        if (!is_numeric($number)) {\n            return false;\n        }\n\n        return $number % 2 == 0;\n    }\n}\n``\n\nNow you can extend a validator just as you would do in a normal class, like this:\n\n```php\n\u003c?php\nclass IsAlsoEvenValidator extends IsEvenValidator\n{\n    protected $rules = [\n        'age' =\u003e 'required|even',   // this uses the validateEven method from the IsEvenValidator\n    ];\n}\n```\n\n## NestedValidators\nSometimes the data that you need to validate contains something that is validated already in another validator. For example if you create a client, with a user, it might be that you have defined a validator for the user already.\nThis means that you have to duplicate the validation data for the user between the client and the user validator. NestedValidation contain a solution for this.\n\nFirst of all, other validators that are used need to be registered in the validator. This is done as follows:\n\n```php\n\u003c?php\nclass FooValidator extends \\CodeYellow\\Validation\\Validator\n{\n    protected $validators = [\n        'bar' =\u003e 'Foo\\\\BarValidator'\n    ];\n```\nNow we can reference the 'bar' validator when specifying rules\n\n__nested validator__\n\nThe nested validator can be applied by adding 'nested:validator\\_name' in the rules. So for example:\n\n```php\n\u003c?php\n    protected $rules = [\n        'nested' =\u003e 'array|nested:bar'\n    ];\n```\n\nThe bar validator will now be called on the value of the nested key\n\n\n__nested collection validator__\n\nThe nested collection is almost the same as the nested validator. The only difference is that in the rules 'nested\\_collection:validator\\_name' needs to be used.\n\nE.g.\n```php\n\u003c?php\n    protected $rules = [\n        'nested_collection' =\u003e 'array|nested_collection:bar'\n    ];\n```\n\nNow assume that we have a validator for bar as follows:\n\n```php\nclass BarValidator extends IsEvenValidator\n{\n    protected $rules = [\n        'age' =\u003e 'required|even',   // this uses the validateEven method from the IsEvenValidator\n    ];\n}\n```\n\nNow we can use the fooValidator as follows:\n```php\n$fooValidator = app()-\u003emake('FooValidator');\n\n$bar = ['age' =\u003e 6];\n$otherBar = ['age' =\u003e 8];\n$badBar = ['age' =\u003e 7];\n\n$fooValidator-\u003evalidate([\n    'nested' =\u003e $bar\n]); // Returns true, since $bar passes the BarValidator\n\n$fooValidator-\u003evalidate([\n    'nested' =\u003e $badBar\n]); // Returns false, since $badBar does not pass the BarValidator\n\n\n$fooValidator-\u003evalidate([\n    'nested_collection' =\u003e [$bar, $otherBar]\n]); // Returns true, since $bar and $otherBar passes the BarValidator\n\n$fooValidator-\u003evalidate([\n    'nested' =\u003e [$bar, $badBar]\n]); // Returns false, since $badBar does not pass the BarValidator\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeyellowbv%2Fvalidator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcodeyellowbv%2Fvalidator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcodeyellowbv%2Fvalidator/lists"}