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

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

kalani/validation-rule-generator
================================

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

v0.2.0(7y ago)81.0k7PHPPHP &gt;=7.2.0

Since Aug 4Pushed 7y ago1 watchersCompare

[ Source](https://github.com/jijoel/validation-rule-generator)[ Packagist](https://packagist.org/packages/kalani/validation-rule-generator)[ RSS](/packages/kalani-validation-rule-generator/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (5)Versions (4)Used By (0)

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

[](#validation-rule-generator)

This 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 make:validation` 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 make:validation [--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);

```

Development
===========

[](#development)

We are using mysql for database testing because sqlite does not include as many data types. In mysql, create a database, user, and password:

```
CREATE DATABASE test_lrg;
CREATE USER 'test_lrg'@'localhost' IDENTIFIED WITH mysql_native_password BY 'Password1234!';
GRANT ALL ON test_lrg.* TO 'test_lrg'@'localhost';

```

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity23

Limited adoption so far

Community12

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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 ~2029 days

Total

2

Last Release

2684d ago

PHP version history (2 changes)v0.1.0PHP &gt;=5.3.0

v0.2.0PHP &gt;=7.2.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/3487641?v=4)[Joel](/maintainers/jijoel)[@jijoel](https://github.com/jijoel)

![](https://avatars.githubusercontent.com/u/1280825?v=4)[Kalani](/maintainers/kalani)[@Kalani](https://github.com/Kalani)

---

Top Contributors

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

---

Tags

laravelschemavalidation

###  Code Quality

TestsPHPUnit

### Embed Badge

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

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

###  Alternatives

[wendelladriel/laravel-validated-dto

Data Transfer Objects with validation for Laravel applications

761621.7k17](/packages/wendelladriel-laravel-validated-dto)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

2422.3M6](/packages/laravel-validation-rules-credit-card)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3883.5M1](/packages/axlon-laravel-postal-code-validation)[illuminatech/validation-composite

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

180517.4k](/packages/illuminatech-validation-composite)[venturedrake/laravel-crm

A free open source CRM built as a package for laravel projects

42010.0k](/packages/venturedrake-laravel-crm)[romegasoftware/laravel-schema-generator

Generate TypeScript Zod validation schemas from Laravel validation rules

3015.3k](/packages/romegasoftware-laravel-schema-generator)

PHPackages © 2026

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