Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
L

laravel-schema-rules

> 后端框架
Open source

Automatically generate Laravel validation rules based on your database table schema!

363 stars0 likes1 views
WebsiteGitHub

About

Automatically generate Laravel validation rules based on your database table schema!

Laravel Schema Rules

Automatically generate basic Laravel validation rules based on your database table schema! Use these as a starting point to fine-tune and optimize your validation rules as needed.

Here you can use the web version, if you like: https://validationforlaravel.com

Installation

You can install the package via composer:

bash
composer require laracraft-tech/laravel-schema-rules --dev

Then publish the config file with:

bash
php artisan vendor:publish --tag="schema-rules-config"

ToC

  • Laravel Schema Rules
    • Installation
    • ToC
    • Usage
      • Generate rules for a whole table
      • Generate rules for specific columns
      • Generate Form Request Class
      • Always skip columns
    • Supported Drivers
    • Testing
    • Changelog
    • Contributing
    • Security Vulnerabilities
    • Credits
    • License

Usage

Let's say you've migrated this fictional table:

…

Generate rules for a whole table

Now if you run:

php artisan schema:generate-rules persons

You'll get:

…

As you may have noticed the float-column body_size, just gets generated to ['required', 'numeric']. Proper rules for float, decimal and double, are not yet implemented!

Generate rules for specific columns

You can also explicitly specify the columns:

php artisan schema:generate-rules persons --columns first_name,last_name,email

Which gives you:

Schema-based validation rules for table "persons" have been generated!
Copy & paste these to your controller validation or form request or where ever your validation takes place:
[
    'first_name' => ['required', 'string', 'min:1', 'max:100'],
    'last_name' => ['required', 'string', 'min:1', 'max:100'],
    'email' => ['required', 'string', 'min:1', 'max:255']
]

Generate Form Request Class

Optionally, you can add a --create-request or -c flag, which will create a form request class with the generated rules for you!

…

Always skip columns

To always skip columns add it in the config file, under skip_columns parameter.

php
'skip_columns' => ['whatever', 'some_other_column'],

Supported Drivers

Currently, the supported database drivers are MySQL, PostgreSQL, and SQLite.

Please note, since each driver supports different data types and range specifications, the validation rules generated by this package may vary depending on the database driver you are using.

Testing

Before 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.

bash
composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

  • Zacharias Creutznacher
  • All Contributors

License

The MIT License (MIT). Please see License File for more information.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

PHPlaravelphprulesvalidation-rules

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category后端框架
PricingOpen source

> Related tools

N
Node.js
基于 V8 的 JavaScript 运行时
D
Django
Python 高级 Web 框架
S
Spring Boot
Java 生态主流微服务框架