PHPackages                             spmsupun/validation-rule-generator - 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. spmsupun/validation-rule-generator

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

spmsupun/validation-rule-generator
==================================

Laravel 4 class to automatically generate validation rules based on table schema

0.0.2(7y ago)07MITPHPPHP &gt;=7.1

Since Sep 3Pushed 7y ago1 watchersCompare

[ Source](https://github.com/spmsupun/validation-rule-generator)[ Packagist](https://packagist.org/packages/spmsupun/validation-rule-generator)[ RSS](/packages/spmsupun-validation-rule-generator/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (3)Versions (3)Used By (0)

Validation Rule Generator
=========================

[](#validation-rule-generator)

This Laravel 4 package will automatically generate laravel validation rules, based on your schema. It can generate rules for:

- All tables in the database
- One (given) table
- One (given) column from a (given) table

Pass in custom rules to override the automatically generated rules.

You can use the results from the ValidationRuleGenerator directly in a validator, or you can copy them from an Artisan command, and manually enter them into your models.

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

[](#installation)

Install the package via Composer. Edit your `composer.json` file to require `kalani/validation-rule-generator`.

```
"require": {
    "laravel/framework": "4.0.*",
    "kalani/validation-rule-generator": "dev-master"
}
```

Next, update Composer from the terminal:

```
composer update

```

Finally, add the service provider to the providers array in `app\config\app.php`:

```
'Kalani\ValidationRuleGenerator\ValidationRuleGeneratorServiceProvider',

```

There is already an alias set up for `ValidationRuleGenerator`, but if you would like to refer to it by a short, memorable name in your app, you can add another alias as follows:

```
'Rules' => 'Kalani\ValidationRuleGenerator\Facades\ValidationRuleGenerator',

```

(We will use ValidationRuleGenerator and Rules interchangeably)

Usage
-----

[](#usage)

#### Artisan Command

[](#artisan-command)

`php artisan generate:rules` will generate rules for a given table or model. These rules will be printed in a format that you could copy directly to another php file.

On the command line, you can run the rule generator as follows:

```
php artisan generate:rules [--model="..."] [--table="..."] [--all]

```

One of these parameters is required:

```
--all               Output table information for all tables in the database
--table=table_name  Returns rules for the given table
--model=ModelName   Returns rules for the given model (with overrides)

```

If you pass in a `--model` parameter, the rule generator will generate rules for the model's table, and will then merge it with the model's $rules array. In cases of a conflict, the $rules array will take precedence.

#### Pass directly into validator

[](#pass-directly-into-validator)

Call `ValidationRuleGenerator::getRules($table|$model, $column, $rules, $id)`:

```
* `$table`  The name of the table (or model object) for which to get rules
* `$column` The name of the column
* `$rules`  Custom rules (override automatically generated rules)
* `$id`     Ignore unique rules for the given id

```

All of the parameters are optional. If you do not include any, the package will return an array of all rules in the database. If you include the $table, rules will be gathered from that table; $table and $column, rules will be gathered for the given table/column.

To validate a table:

```
$valid = Validator::make(Input::all(), Rules::getRules($tableName));

```

To validate a table, ignoring a given id:

```
$valid = Validator::make(Input::all(), Rules::getRules($tableName, null, null, $id));

```

### Alternative Usage

[](#alternative-usage)

To get all of the rules for a table, in your controller:

```
$rules = ValidationRuleGenerator::getTableRules($model->getTable(), array($custom_rules));
$validation = Validator::make(Input::all(), $rules);

```

You can also generate rules to ignore the current record id:

```
$rules = ValidationRuleGenerator::getUniqueRules($rules, $id);

```

If you'd like an array of all validation rules for all tables in your database:

```
$rules = ValidationRuleGenerator::getAllRules();

```

If you'd like validation rules for one column:

```
$rules = ValidationRuleGenerator::getColumnRules($table, $column);

```

###  Health Score

22

—

LowBetter than 23% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community9

Small or concentrated contributor base

Maturity48

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 69.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 ~0 days

Total

2

Last Release

2805d ago

### Community

Maintainers

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

---

Top Contributors

[![jijoel](https://avatars.githubusercontent.com/u/3487641?v=4)](https://github.com/jijoel "jijoel (9 commits)")[![spmsupun](https://avatars.githubusercontent.com/u/1854023?v=4)](https://github.com/spmsupun "spmsupun (4 commits)")

---

Tags

laravelschemavalidation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/spmsupun-validation-rule-generator/health.svg)

```
[![Health](https://phpackages.com/badges/spmsupun-validation-rule-generator/health.svg)](https://phpackages.com/packages/spmsupun-validation-rule-generator)
```

###  Alternatives

[propaganistas/laravel-phone

Adds phone number functionality to Laravel based on Google's libphonenumber API.

3.0k35.7M106](/packages/propaganistas-laravel-phone)[proengsoft/laravel-jsvalidation

Validate forms transparently with Javascript reusing your Laravel Validation Rules, Messages, and FormRequest

1.1k2.3M49](/packages/proengsoft-laravel-jsvalidation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

759569.4k13](/packages/wendelladriel-laravel-validated-dto)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2412.2M5](/packages/laravel-validation-rules-credit-card)[illuminatech/validation-composite

Allows uniting several validation rules into a single one for easy re-usage

184485.5k](/packages/illuminatech-validation-composite)

PHPackages © 2026

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