{"id":21461664,"url":"https://github.com/gabrieljmj/laravel-rule-sets","last_synced_at":"2026-05-19T00:35:20.438Z","repository":{"id":55086732,"uuid":"235819788","full_name":"gabrieljmj/laravel-rule-sets","owner":"gabrieljmj","description":":book: Avoid repeating rules sets through requests.","archived":false,"fork":false,"pushed_at":"2026-01-28T00:00:47.000Z","size":67,"stargazers_count":2,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-30T17:06:52.346Z","etag":null,"topics":["laravel","rules","validation"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gabrieljmj.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-23T15:07:29.000Z","updated_at":"2021-01-13T17:50:56.000Z","dependencies_parsed_at":"2022-08-14T11:31:21.913Z","dependency_job_id":null,"html_url":"https://github.com/gabrieljmj/laravel-rule-sets","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/gabrieljmj/laravel-rule-sets","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljmj%2Flaravel-rule-sets","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljmj%2Flaravel-rule-sets/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljmj%2Flaravel-rule-sets/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljmj%2Flaravel-rule-sets/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gabrieljmj","download_url":"https://codeload.github.com/gabrieljmj/laravel-rule-sets/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gabrieljmj%2Flaravel-rule-sets/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33196185,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: 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":["laravel","rules","validation"],"created_at":"2024-11-23T07:10:25.480Z","updated_at":"2026-05-19T00:35:20.423Z","avatar_url":"https://github.com/gabrieljmj.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Rule Sets\n\n![Travis (.com)](https://img.shields.io/travis/com/gabrieljmj/laravel-rule-sets) ![Packagist](https://img.shields.io/packagist/l/gabrieljmj/laravel-rule-sets)\n\nAvoid repeating validation rules sets. With this library it is possible to share rules between sets and reuse sets through requests.\n\n## Installing\n\n### Composer\n\nExecute the following command:\n\n```terminal\ncomposer require gabrieljmj/laravel-rule-sets\n```\n\n#### For Laravel before 5.5\n\nIt is necessary to add the service provider to the providers list at ```config/app.php```:\n\n```php\nGabrieljmj\\LaravelRuleSets\\Providers\\RuleSetsServiceProvider::class,\n```\n\n## Usage\n\nThe package provides the artisan command ```make:rule-set```. It will generate a RuleSet at the namespace ```App\\Rules\\RuleSets```.\n\n```terminal\nartisan make:rule-set UserRuleSet\n```\n\nAdd the necessary rules at the protected method ```rules``` of the set.\n\n```php\n\u003c?php\n\nnamespace App\\Rules\\RuleSets;\n\nuse Gabrieljmj\\LaravelRuleSets\\AbstractRuleSet;\n\nclass UserRuleSet extends AbstractRuleSet\n{\n    protected function rules(): array\n    {\n        return [\n            'username' =\u003e 'required',\n            'email' =\u003e 'required|email',\n            'password' =\u003e 'required|min:8|confirmed',\n        ];\n    }\n}\n```\n\nThen you can now inject into the ```rules``` method of the request.\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Requests;\n\nuse Illuminate\\Foundation\\Http\\FormRequest;\nuse App\\Rules\\RuleSets\\UserRuleSet;\n\nclass UserRequest extends FormRequest\n{\n    // ...\n\n    public function rules(UserRuleSet $userRules)\n    {\n        return $userRules-\u003egetRules();\n    }\n}\n```\n\n### Combinig rules sets\n\n#### ```combineWithRules(array $rules)```\n\nThis method will be used to inject rules into the rule set object.\n\n\u003e **Note:** Rules with the same name will be overridden by the new ones.\n\n```php\nuse App\\Rules\\RuleSets\\UserRuleSet;\nuse App\\Rules\\RuleSets\\PasswordRuleSet;\n\n// ...\n\npublic function rules(UserRuleSet $userRules, PasswordRuleSet $passwordRuleSet)\n{\n    return $userRules\n        -\u003ecombineWith([$passwordRuleSet])\n        -\u003egetRules();\n}\n```\n\n#### ```$combineWith```\n\nAn array with sets that will be inject to the rules collection on the ```getRules``` execution.\n\n```php\n\u003c?php\n\nnamespace App\\Rules\\RuleSets;\n\nuse Gabrieljmj\\LaravelRuleSets\\AbstractRuleSet;\n\nclass PersonRuleSet extends AbstractRuleSet\n{\n    protected function rules(): array\n    {\n        return [\n            'name' =\u003e 'required',\n        ];\n    }\n}\n```\n\n```php\n\u003c?php\n\nnamespace App\\Rules\\RuleSets;\n\nuse Gabrieljmj\\LaravelRuleSets\\AbstractRuleSet;\n\nclass UserRuleSet extends AbstractRuleSet\n{\n    public function __construct(PersonRuleSet $personRuleSet)\n    {\n        // Adds other rule set\n        $this-\u003ecombineWith[] = $personRuleSet;\n    }\n\n    protected function rules(): array\n    {\n        return [\n            'email' =\u003e 'required|email',\n            'password' =\u003e 'required|min:8|confirmed',\n        ];\n    }\n}\n```\n\n```php\n$userRuleSet-\u003egetRules(); // ['email' =\u003e '...', 'password' =\u003e '...', 'name' =\u003e '...']\n```\n\n##### Override rules\n\nSometimes two sets will have the a rule for a input. The preferred will be from the combined with set. If it's necessary the ```getRules``` method to override the rules, just set protected property ```$overrideRules``` of the set to ```true```.\n\n```php\n\u003c?php\n\nnamespace App\\Rules\\RuleSets;\n\nuse Gabrieljmj\\LaravelRuleSets\\AbstractRuleSet;\n\nclass UserRuleSet extends AbstractRuleSet\n{\n    protected $overrideRules = true;\n\n    public function __construct(PersonRuleSet $personRuleSet)\n    {\n        $this-\u003ecombineWith[] = $personRuleSet;\n    }\n\n    protected function rules(): array\n    {\n        return [\n            'email' =\u003e 'required|email',\n            'password' =\u003e 'required|min:8|confirmed',\n            'name' =\u003e 'required|length:25',\n        ];\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrieljmj%2Flaravel-rule-sets","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgabrieljmj%2Flaravel-rule-sets","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgabrieljmj%2Flaravel-rule-sets/lists"}