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.5.0(1y ago)36257.9k↑38.1%23[1 PRs](https://github.com/laracraft-tech/laravel-schema-rules/pulls)MITPHPPHP ^7.4 || ^8.0 || ^8.1CI passing

Since Jun 19Pushed 3mo 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 1mo ago

READMEChangelog (10)Dependencies (13)Versions (15)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)

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

52

—

FairBetter than 96% of packages

Maintenance63

Regular maintenance activity

Popularity50

Moderate usage in the ecosystem

Community21

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 63.2% 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 ~51 days

Recently: every ~113 days

Total

13

Last Release

450d 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 (103 commits)")[![dependabot[bot]](https://avatars.githubusercontent.com/in/29110?v=4)](https://github.com/dependabot[bot] "dependabot[bot] (21 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] (11 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

[spatie/laravel-health

Monitor the health of a Laravel application

86910.0M83](/packages/spatie-laravel-health)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9682.1M97](/packages/roots-acorn)[laracraft-tech/laravel-useful-additions

A collection of useful Laravel additions!

58109.4k](/packages/laracraft-tech-laravel-useful-additions)[dyrynda/laravel-model-uuid

This package allows you to easily work with UUIDs in your Laravel models.

4802.8M8](/packages/dyrynda-laravel-model-uuid)[clickbar/laravel-magellan

This package provides functionality for working with the postgis extension in Laravel.

423715.4k1](/packages/clickbar-laravel-magellan)[defstudio/pest-plugin-laravel-expectations

A plugin to add laravel tailored expectations to Pest

98548.9k4](/packages/defstudio-pest-plugin-laravel-expectations)

PHPackages © 2026

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