PHPackages                             laracraft-tech/laravel-schema-rules - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Validation &amp; Sanitization](/categories/validation)
4. /
5. laracraft-tech/laravel-schema-rules

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

laracraft-tech/laravel-schema-rules
===================================

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

v1.6.0(3mo ago)36364.5k—0.9%24MITPHPPHP ^7.4 || ^8.0 || ^8.1CI passing

Since Jun 19Pushed 1w ago7 watchersCompare

[ Source](https://github.com/laracraft-tech/laravel-schema-rules)[ Packagist](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)[ Docs](https://github.com/laracraft-tech/laravel-schema-rules)[ RSS](/packages/laracraft-tech-laravel-schema-rules/feed)WikiDiscussions main Synced 3d ago

READMEChangelog (10)Dependencies (26)Versions (16)Used By (0)

Laravel Schema Rules
====================

[](#laravel-schema-rules)

[![Latest Version on Packagist](https://camo.githubusercontent.com/05ab02217a8926cbee18753c62561e0618de8e706b1bdcf2b3d4133f392cbdd0/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6c61726163726166742d746563682f6c61726176656c2d736368656d612d72756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)[![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)[![Check & 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)[![License](https://camo.githubusercontent.com/883f7f991c7ca3845438b45c81dea588d75b257666695be367e2bc628e79e69b/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f6c61726163726166742d746563682f6c61726176656c2d736368656d612d72756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)[![Total Downloads](https://camo.githubusercontent.com/401c2a31a74ab4aafbf050d17ed0fe59a52f75994514f7e25aea72926a58ae8d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c61726163726166742d746563682f6c61726176656c2d736368656d612d72756c65732e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/laracraft-tech/laravel-schema-rules)[![Laravel Compatibility](https://camo.githubusercontent.com/d7281df1e017a516f958361b13776fc69b510e4a1d54a62b860ba4cef016645e/68747470733a2f2f62616467652e6c61726176656c2e636c6f75642f62616467652f6c61726163726166742d746563682f6c61726176656c2d736368656d612d72756c6573)](https://packagist.org/packages/laracraft-tech/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:

Installation
------------

[](#installation)

You can install the package via composer:

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

Then publish the config file with:

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

ToC
---

[](#toc)

- [Laravel Schema Rules](#laravel-schema-rules)
    - [Installation](#installation)
    - [ToC](#toc)
    - [Usage](#usage)
        - [Generate rules for a whole table](#generate-rules-for-a-whole-table)
        - [Generate rules for specific columns](#generate-rules-for-specific-columns)
        - [Generate Form Request Class](#generate-form-request-class)
        - [Always skip columns](#always-skip-columns)
    - [Supported Drivers](#supported-drivers)
    - [Testing](#testing)
    - [Changelog](#changelog)
    - [Contributing](#contributing)
    - [Security Vulnerabilities](#security-vulnerabilities)
    - [Credits](#credits)
    - [License](#license)

Usage
-----

[](#usage)

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

```
Schema::create('persons', function (Blueprint $table) {
    $table->id();
    $table->string('first_name', 100);
    $table->string('last_name', 100);
    $table->string('email');
    $table->foreignId('address_id')->constrained();
    $table->text('bio')->nullable();
    $table->enum('gender', ['m', 'f', 'd']);
    $table->date('birth');
    $table->year('graduated');
    $table->float('body_size');
    $table->unsignedTinyInteger('children_count')->nullable();
    $table->integer('account_balance');
    $table->unsignedInteger('net_income');
    $table->boolean('send_newsletter')->nullable();
});
```

### Generate rules for a whole table

[](#generate-rules-for-a-whole-table)

Now if you run:

`php artisan schema:generate-rules persons`

You'll get:

```
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'],
    'address_id' => ['required', 'exists:addresses,id'],
    'bio' => ['nullable', 'string', 'min:1'],
    'gender' => ['required', 'string', 'in:m,f,d'],
    'birth' => ['required', 'date'],
    'graduated' => ['required', 'integer', 'min:1901', 'max:2155'],
    'body_size' => ['required', 'numeric'],
    'children_count' => ['nullable', 'integer', 'min:0', 'max:255'],
    'account_balance' => ['required', 'integer', 'min:-2147483648', 'max:2147483647'],
    'net_income' => ['required', 'integer', 'min:0', 'max:4294967295'],
    'send_newsletter' => ['nullable', 'boolean']
]

```

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

[](#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

[](#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!

```
# creates app/Http/Requests/StorePersonRequest.php (store request is the default)
php artisan schema:generate-rules persons --create-request

# creates/overwrites app/Http/Requests/StorePersonRequest.php
php artisan schema:generate-rules persons --create-request --force

# creates app/Http/Requests/UpdatePersonRequest.php
php artisan schema:generate-rules persons --create-request --file UpdatePersonRequest

# creates app/Http/Requests/Api/V1/StorePersonRequest.php
php artisan schema:generate-rules persons --create-request --file Api\\V1\\StorePersonRequest

# creates/overwrites app/Http/Requests/Api/V1/StorePersonRequest.php (using shortcuts)
php artisan schema:generate-rules persons -cf --file Api\\V1\\StorePersonRequest
```

### Always skip columns

[](#always-skip-columns)

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

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

Supported Drivers
-----------------

[](#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
-------

[](#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.

```
composer test
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) for details.

Security Vulnerabilities
------------------------

[](#security-vulnerabilities)

Please review [our security policy](../../security/policy) on how to report security vulnerabilities.

Credits
-------

[](#credits)

- [Zacharias Creutznacher](https://github.com/laracraft-tech)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

59

—

FairBetter than 98% of packages

Maintenance91

Actively maintained with recent releases

Popularity50

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity61

Established project with proven stability

 Bus Factor1

Top contributor holds 62.5% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~78 days

Recently: every ~211 days

Total

14

Last Release

94d ago

PHP version history (2 changes)v1.0.0PHP ^7.4 || ^8.0

v1.4.0PHP ^7.4 || ^8.0 || ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/cf347b32c0d1fceabbcbce7626ad662faa34738396fd9f774231d55370823713?d=identicon)[Sairahcaz](/maintainers/Sairahcaz)

---

Top Contributors

[![Sairahcaz](https://avatars.githubusercontent.com/u/7384870?v=4)](https://github.com/Sairahcaz "Sairahcaz (105 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (23 commits)")[![giagara](https://avatars.githubusercontent.com/u/79515022?v=4)](https://github.com/giagara "giagara (14 commits)")[![github-actions[bot]](https://avatars.githubusercontent.com/in/15368?v=4)](https://github.com/github-actions[bot] "github-actions[bot] (12 commits)")[![dreammonkey](https://avatars.githubusercontent.com/u/371355?v=4)](https://github.com/dreammonkey "dreammonkey (10 commits)")[![laravel-shift](https://avatars.githubusercontent.com/u/15991828?v=4)](https://github.com/laravel-shift "laravel-shift (3 commits)")[![mathieutu](https://avatars.githubusercontent.com/u/11351322?v=4)](https://github.com/mathieutu "mathieutu (1 commits)")

---

Tags

laravelphprulesvalidation-ruleslaravellaracraft-techlaravel-schema-rules

###  Code Quality

TestsPest

Code StylePHP CS Fixer

### Embed Badge

![Health badge](/badges/laracraft-tech-laravel-schema-rules/health.svg)

```
[![Health](https://phpackages.com/badges/laracraft-tech-laravel-schema-rules/health.svg)](https://phpackages.com/packages/laracraft-tech-laravel-schema-rules)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[spatie/laravel-health

Monitor the health of a Laravel application

87512.0M165](/packages/spatie-laravel-health)[laravel/ai

The official AI SDK for Laravel.

1.0k3.2M195](/packages/laravel-ai)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[simplestats-io/laravel-client

Server-side analytics for Laravel that follows the full funnel from visit to registration to payment, attributed to the channel that drove it. Revenue, MRR, churn and ad-spend profit (ROAS/CAC) per channel. GDPR compliant, ad-blocker proof.

5021.9k](/packages/simplestats-io-laravel-client)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
