{"id":13593649,"url":"https://github.com/laracraft-tech/laravel-schema-rules","last_synced_at":"2026-01-30T06:42:20.728Z","repository":{"id":176569889,"uuid":"648796222","full_name":"laracraft-tech/laravel-schema-rules","owner":"laracraft-tech","description":"Automatically generate Laravel validation rules based on your database table schema!","archived":false,"fork":false,"pushed_at":"2024-08-13T07:17:09.000Z","size":116,"stargazers_count":348,"open_issues_count":0,"forks_count":22,"subscribers_count":7,"default_branch":"main","last_synced_at":"2024-10-13T14:16:46.837Z","etag":null,"topics":["laravel","php","rules","validation-rules"],"latest_commit_sha":null,"homepage":"https://laracraft.tech/blog/how-to-generate-validation-rules-based-on-your-database-table-schema","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/laracraft-tech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","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":"2023-06-02T20:48:53.000Z","updated_at":"2024-10-12T22:11:05.000Z","dependencies_parsed_at":"2023-10-11T11:23:34.711Z","dependency_job_id":"8f61e841-2844-4212-90a4-ad7579eb0a86","html_url":"https://github.com/laracraft-tech/laravel-schema-rules","commit_stats":null,"previous_names":["laracraft-tech/laravel-schema-rules"],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracraft-tech%2Flaravel-schema-rules","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracraft-tech%2Flaravel-schema-rules/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracraft-tech%2Flaravel-schema-rules/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/laracraft-tech%2Flaravel-schema-rules/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/laracraft-tech","download_url":"https://codeload.github.com/laracraft-tech/laravel-schema-rules/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223365422,"owners_count":17133713,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","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","php","rules","validation-rules"],"created_at":"2024-08-01T16:01:22.647Z","updated_at":"2026-01-30T06:42:20.669Z","avatar_url":"https://github.com/laracraft-tech.png","language":"PHP","funding_links":[],"categories":["PHP"],"sub_categories":[],"readme":"# Laravel Schema Rules\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/laracraft-tech/laravel-schema-rules.svg?style=flat-square)](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)\n[![Tests](https://github.com/laracraft-tech/laravel-schema-rules/actions/workflows/run-tests.yml/badge.svg?branch=main)](https://github.com/laracraft-tech/laravel-schema-rules/actions/workflows/run-tests.yml)\n[![Check \u0026 fix styling](https://github.com/laracraft-tech/laravel-schema-rules/actions/workflows/fix-php-code-style-issues.yml/badge.svg?branch=main)](https://github.com/laracraft-tech/laravel-schema-rules/actions/workflows/fix-php-code-style-issues.yml)\n[![License](https://img.shields.io/packagist/l/laracraft-tech/laravel-schema-rules.svg?style=flat-square)](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)\n[![Total Downloads](https://img.shields.io/packagist/dt/laracraft-tech/laravel-schema-rules.svg?style=flat-square)](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)\n\nAutomatically generate basic Laravel validation rules based on your database table schema!\nUse these as a starting point to fine-tune and optimize your validation rules as needed.\n\nHere you can use the web version, if you like: [https://validationforlaravel.com](https://validationforlaravel.com)\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require laracraft-tech/laravel-schema-rules --dev\n```\n\nThen publish the config file with:\n\n```bash\nphp artisan vendor:publish --tag=\"schema-rules-config\"\n```\n\n## ToC\n\n-   [Laravel Schema Rules](#laravel-schema-rules)\n    -   [Installation](#installation)\n    -   [ToC](#toc)\n    -   [Usage](#usage)\n        -   [Generate rules for a whole table](#generate-rules-for-a-whole-table)\n        -   [Generate rules for specific columns](#generate-rules-for-specific-columns)\n        -   [Generate Form Request Class](#generate-form-request-class)\n        -   [Always skip columns](#always-skip-columns)\n    -   [Supported Drivers](#supported-drivers)\n    -   [Testing](#testing)\n    -   [Changelog](#changelog)\n    -   [Contributing](#contributing)\n    -   [Security Vulnerabilities](#security-vulnerabilities)\n    -   [Credits](#credits)\n    -   [License](#license)\n\n## Usage\n\nLet's say you've migrated this fictional table:\n\n```php\nSchema::create('persons', function (Blueprint $table) {\n    $table-\u003eid();\n    $table-\u003estring('first_name', 100);\n    $table-\u003estring('last_name', 100);\n    $table-\u003estring('email');\n    $table-\u003eforeignId('address_id')-\u003econstrained();\n    $table-\u003etext('bio')-\u003enullable();\n    $table-\u003eenum('gender', ['m', 'f', 'd']);\n    $table-\u003edate('birth');\n    $table-\u003eyear('graduated');\n    $table-\u003efloat('body_size');\n    $table-\u003eunsignedTinyInteger('children_count')-\u003enullable();\n    $table-\u003einteger('account_balance');\n    $table-\u003eunsignedInteger('net_income');\n    $table-\u003eboolean('send_newsletter')-\u003enullable();\n});\n```\n\n### Generate rules for a whole table\n\nNow if you run:\n\n`php artisan schema:generate-rules persons`\n\nYou'll get:\n\n```\nSchema-based validation rules for table \"persons\" have been generated!\nCopy \u0026 paste these to your controller validation or form request or where ever your validation takes place:\n[\n    'first_name' =\u003e ['required', 'string', 'min:1', 'max:100'],\n    'last_name' =\u003e ['required', 'string', 'min:1', 'max:100'],\n    'email' =\u003e ['required', 'string', 'min:1', 'max:255'],\n    'address_id' =\u003e ['required', 'exists:addresses,id'],\n    'bio' =\u003e ['nullable', 'string', 'min:1'],\n    'gender' =\u003e ['required', 'string', 'in:m,f,d'],\n    'birth' =\u003e ['required', 'date'],\n    'graduated' =\u003e ['required', 'integer', 'min:1901', 'max:2155'],\n    'body_size' =\u003e ['required', 'numeric'],\n    'children_count' =\u003e ['nullable', 'integer', 'min:0', 'max:255'],\n    'account_balance' =\u003e ['required', 'integer', 'min:-2147483648', 'max:2147483647'],\n    'net_income' =\u003e ['required', 'integer', 'min:0', 'max:4294967295'],\n    'send_newsletter' =\u003e ['nullable', 'boolean']\n]\n```\n\nAs you may have noticed the float-column `body_size`, just gets generated to `['required', 'numeric']`.\nProper rules for `float`, `decimal` and `double`, are not yet implemented!\n\n### Generate rules for specific columns\n\nYou can also explicitly specify the columns:\n\n`php artisan schema:generate-rules persons --columns first_name,last_name,email`\n\nWhich gives you:\n\n```\nSchema-based validation rules for table \"persons\" have been generated!\nCopy \u0026 paste these to your controller validation or form request or where ever your validation takes place:\n[\n    'first_name' =\u003e ['required', 'string', 'min:1', 'max:100'],\n    'last_name' =\u003e ['required', 'string', 'min:1', 'max:100'],\n    'email' =\u003e ['required', 'string', 'min:1', 'max:255']\n]\n```\n\n### Generate Form Request Class\n\nOptionally, you can add a `--create-request` or `-c` flag,\nwhich will create a form request class with the generated rules for you!\n\n```bash\n# creates app/Http/Requests/StorePersonRequest.php (store request is the default)\nphp artisan schema:generate-rules persons --create-request\n\n# creates/overwrites app/Http/Requests/StorePersonRequest.php\nphp artisan schema:generate-rules persons --create-request --force\n\n# creates app/Http/Requests/UpdatePersonRequest.php\nphp artisan schema:generate-rules persons --create-request --file UpdatePersonRequest\n\n# creates app/Http/Requests/Api/V1/StorePersonRequest.php\nphp artisan schema:generate-rules persons --create-request --file Api\\\\V1\\\\StorePersonRequest\n\n# creates/overwrites app/Http/Requests/Api/V1/StorePersonRequest.php (using shortcuts)\nphp artisan schema:generate-rules persons -cf --file Api\\\\V1\\\\StorePersonRequest\n```\n\n### Always skip columns\n\nTo always skip columns add it in the config file, under `skip_columns` parameter.\n\n```php\n'skip_columns' =\u003e ['whatever', 'some_other_column'],\n```\n\n## Supported Drivers\n\nCurrently, the supported database drivers are `MySQL`, `PostgreSQL`, and `SQLite`.\n\nPlease note, since each driver supports different data types and range specifications,\nthe validation rules generated by this package may vary depending on the database driver you are using.\n\n## Testing\n\nBefore running tests, you need to set up a local MySQL database named `laravel_schema_rules` and update its _username_ and _password_ in the `phpunit.xml.dist` file.\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n-   [Zacharias Creutznacher](https://github.com/laracraft-tech)\n-   [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaracraft-tech%2Flaravel-schema-rules","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flaracraft-tech%2Flaravel-schema-rules","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flaracraft-tech%2Flaravel-schema-rules/lists"}