百科.dev
全部条目在线工具AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
L

laravel-schema-rules

> 后端框架
开源

根据数据库表结构自动生成 Laravel 验证规则!

363 stars0 点赞1 次浏览
访问官网GitHub

工具介绍

根据数据库表结构自动生成 Laravel 验证规则!

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 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

PHPlaravelphprulesvalidation-rules

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类后端框架
定价开源

> 相关工具

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