PHPackages                             weloveahmed/laravel-auto-validator - 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. weloveahmed/laravel-auto-validator

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

weloveahmed/laravel-auto-validator
==================================

Automatic validation rules generation for Laravel Eloquent models based on database schema.

1.0.0(5mo ago)01MITPHPPHP ^8.2CI passing

Since Jan 16Pushed 5mo agoCompare

[ Source](https://github.com/Weloveahmed/laravel-auto-validator)[ Packagist](https://packagist.org/packages/weloveahmed/laravel-auto-validator)[ RSS](/packages/weloveahmed-laravel-auto-validator/feed)WikiDiscussions main Synced today

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

Laravel Auto Validator
======================

[](#laravel-auto-validator)

[![Latest Version on Packagist](https://camo.githubusercontent.com/23cba50d1050d5438083dd587c2fdc78b1588dbf05fdb508fdb5b901c671428c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f77656c6f766561686d65642f6c61726176656c2d6175746f2d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weloveahmed/laravel-auto-validator)[![Total Downloads](https://camo.githubusercontent.com/a694cf6fd822c9b4aeb8745f508eb9264329db2c972803ba087ec62a6cbd60bd/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f77656c6f766561686d65642f6c61726176656c2d6175746f2d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/weloveahmed/laravel-auto-validator)[![License](https://camo.githubusercontent.com/e5f9a8334b0ddde508e280c174d2076f47289a8ba20b7db8a2f2d86313d5e5dc/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f77656c6f766561686d65642f6c61726176656c2d6175746f2d76616c696461746f722e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)

Automatic validation rules generation for any Eloquent model based on database schema introspection.

---

✨ Why this package?
-------------------

[](#-why-this-package)

Laravel validation is powerful, but writing FormRequests for every model/table can become repetitive.

This package automatically generates validation rules based on your database schema:

- Column types
- Length constraints
- Required vs nullable
- Unique indexes
- Foreign keys (`exists` rules)

Then allows you to **customize and extend** rules using:

- Model overrides
- Reusable profiles
- Multi-tenant constraints
- SoftDeletes-aware uniqueness
- JSON deep validation (nested rules)

---

✅ Features
----------

[](#-features)

- **Schema Introspection**: Generate rules from column types, lengths, nullability, unique indexes, and foreign keys.
- **Context-Aware**: Supports `store` and `update` contexts (handles unique ignore automatically).
- **Overrides**: Model-specific overrides via simple PHP files.
- **Profiles**: Reusable validation templates (e.g. `person`, `address`, `api-mobile`).
- **SoftDeletes Aware**: Unique rules can ignore soft-deleted rows.
- **Multi-Tenant Ready**: Add tenant constraints to `unique` and `exists`.
- **JSON Support**: Map JSON columns to arrays and validate nested fields.
- **Performance**: Caching of schema and generated rules.
- **Developer Experience**: Fluent API + optional Artisan generators.

---

📦 Installation
--------------

[](#-installation)

```
composer require weloveahmed/laravel-auto-validator
```

Laravel auto-discovers the Service Provider.

⚙️ Configuration
----------------

[](#️-configuration)

Publish the config file:

```
php artisan vendor:publish --tag=auto-validator-config
```

Config file location: `config/auto-validator.php`

```
return [
    'ignore_columns' => [
        'id',
        'created_at',
        'updated_at',
        'deleted_at',
    ],
    'cache' => [
        'enabled' => true,
        'store' => env('AUTO_VALIDATOR_CACHE_STORE', null),
        'ttl' => 3600,
        'prefix' => 'auto_validator:',
    ],
    'overrides_path' => app_path('AutoValidation'),
    'profiles' => [
        // 'person' => [
        //     'name' => ['required', 'string', 'max:255'],
        // ]
    ],
];
```

⚡ How it works (Internals)
--------------------------

[](#-how-it-works-internals)

The package follows a simple pipeline:

**SchemaReader** → **RuleMapper** → **RuleFactory** → **Overrides** → **Profiles** → **Context**

🚀 Basic Usage
-------------

[](#-basic-usage)

This package is designed to work with any Eloquent model.

### ✅ Generate Store Rules

[](#-generate-store-rules)

```
use Weloveahmed\AutoValidator\Facades\AutoValidator;

$rules = AutoValidator::for(Employee::class)
    ->store()
    ->rules();
```

### ✅ Validate Store Data

[](#-validate-store-data)

```
$data = AutoValidator::for(Employee::class)
    ->store()
    ->validate(request()->all());
```

### ✅ Generate Update Rules

[](#-generate-update-rules)

```
$rules = AutoValidator::for(Employee::class)
    ->update($employee->id)
    ->rules();
```

### ✅ Validate Update Data

[](#-validate-update-data)

```
$data = AutoValidator::for(Employee::class)
    ->update($employee->id)
    ->validate(request()->all());
```

🧩 Model Overrides
-----------------

[](#-model-overrides)

Create a file: `app/AutoValidation/Employee.php`

```
return [
    'email' => ['required', 'email'],
    'mobile' => ['nullable', 'regex:/^(01)[0-9]{9}$/'],
];
```

🧠 Profiles (Reusable Rule Sets)
-------------------------------

[](#-profiles-reusable-rule-sets)

Define profiles in config:

```
'profiles' => [
    'api-mobile' => [
        'mobile' => ['required', 'regex:/^(01)[0-9]{9}$/'],
    ],
],
```

Apply profile:

```
$rules = AutoValidator::for(Employee::class)
    ->profile('api-mobile')
    ->store()
    ->rules();
```

🏢 Multi-Tenancy Support
-----------------------

[](#-multi-tenancy-support)

Implement `TenantResolver`:

```
use Weloveahmed\AutoValidator\Contracts\TenantResolver;

class MyTenantResolver implements TenantResolver
{
    public function enabled(): bool { return true; }
    public function tenantId(): mixed { return tenant('id'); }
    public function tenantKeyName(): string { return 'tenant_id'; }
}
```

Bind it in your `AppServiceProvider`:

```
$this->app->bind(TenantResolver::class, MyTenantResolver::class);
```

🗑 SoftDeletes-Aware Unique Rules
--------------------------------

[](#-softdeletes-aware-unique-rules)

Only needed if your model uses SoftDeletes.

```
AutoValidator::for(Employee::class)
    ->store()
    ->softDeletes()
    ->rules();
```

🧾 JSON Deep Validation
----------------------

[](#-json-deep-validation)

To validate nested JSON data, add overrides:

```
return [
    'grades' => ['nullable', 'array'],
    'grades.*.year' => ['required', 'integer'],
    'grades.*.percentage' => ['required', 'numeric', 'min:0', 'max:100'],
];
```

📦 Bulk Import (Enterprise Feature)
----------------------------------

[](#-bulk-import-enterprise-feature)

```
$results = AutoValidator::for(Employee::class)
    ->store()
    ->bulk()
    ->validateRows($rows);

$validatedRows = $results->validated();
$errors = $results->errors();
```

🛠 Artisan Commands
------------------

[](#-artisan-commands)

```
php artisan autovalidator:request Employee
php artisan autovalidator:override Employee
php artisan autovalidator:profile person
```

✅ Testing
---------

[](#-testing)

```
composer test
```

✅ Compatibility
---------------

[](#-compatibility)

PHP: 8.2+ Laravel: 10+

🔐 Security
----------

[](#-security)

If you discover any security issues, please email:

🤝 Contributing
--------------

[](#-contributing)

Contributions are welcome! Submit PRs with tests.

📄 License
---------

[](#-license)

MIT License. See [LICENSE.md](LICENSE.md)

###  Health Score

33

—

LowBetter than 72% of packages

Maintenance70

Regular maintenance activity

Popularity1

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity47

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

Unknown

Total

1

Last Release

170d ago

### Community

Maintainers

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

---

Top Contributors

[![Weloveahmed](https://avatars.githubusercontent.com/u/75876150?v=4)](https://github.com/Weloveahmed "Weloveahmed (1 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/weloveahmed-laravel-auto-validator/health.svg)

```
[![Health](https://phpackages.com/badges/weloveahmed-laravel-auto-validator/health.svg)](https://phpackages.com/packages/weloveahmed-laravel-auto-validator)
```

###  Alternatives

[livewire/livewire

A front-end framework for Laravel.

23.6k89.0M2.7k](/packages/livewire-livewire)[yajra/laravel-oci8

Oracle DB driver for Laravel via OCI8

8793.2M25](/packages/yajra-laravel-oci8)[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[wearepixel/laravel-cart

A cart implementation for Laravel

1374.8k](/packages/wearepixel-laravel-cart)[api-platform/laravel

API Platform support for Laravel

58171.6k14](/packages/api-platform-laravel)[aedart/athenaeum

Athenaeum is a mono repository; a collection of various PHP packages

245.2k](/packages/aedart-athenaeum)

PHPackages © 2026

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