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

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

youssefhamdane/validation-rule-generator-fixed
==============================================

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

0.4.0(6y ago)05PHPPHP &gt;=7.2.0

Since Aug 4Pushed 6y agoCompare

[ Source](https://github.com/youssefhamdane/validation-rule-generator)[ Packagist](https://packagist.org/packages/youssefhamdane/validation-rule-generator-fixed)[ RSS](/packages/youssefhamdane-validation-rule-generator-fixed/feed)WikiDiscussions master Synced 3d ago

READMEChangelog (2)Dependencies (2)Versions (6)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

23

—

LowBetter than 27% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity52

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 93.1% 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 ~808 days

Total

4

Last Release

2241d 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/13048852?v=4)[youssef](/maintainers/youssefhamdane)[@youssefhamdane](https://github.com/youssefhamdane)

---

Top Contributors

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

---

Tags

laravelschemavalidation

### Embed Badge

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

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

###  Alternatives

[romegasoftware/laravel-schema-generator

Generate TypeScript Zod validation schemas from Laravel validation rules

288.2k](/packages/romegasoftware-laravel-schema-generator)[stuyam/laravel-phone-validator

A phone validator for Laravel using the free Twilio phone lookup service.

2861.3k](/packages/stuyam-laravel-phone-validator)[pacerit/laravel-polish-validation-rules

Simple Polish Validation rules for Laravel and Lumen framework

1449.9k](/packages/pacerit-laravel-polish-validation-rules)[laravel-validation-rules/ip

Validate if an ip address is public or private.

1729.7k](/packages/laravel-validation-rules-ip)[fab2s/dt0

Immutable DTOs with bidirectional casting. No framework required. 8x faster than the alternative.

101.6k1](/packages/fab2s-dt0)

PHPackages © 2026

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