PHPackages                             anlutro/l4-validation - 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. anlutro/l4-validation

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

anlutro/l4-validation
=====================

Validation service class for Laravel.

0.5.6(11y ago)1112.3k↓80%1MITPHPPHP &gt;=5.4.0

Since Jan 13Pushed 11y ago2 watchersCompare

[ Source](https://github.com/anlutro/laravel-validation)[ Packagist](https://packagist.org/packages/anlutro/l4-validation)[ RSS](/packages/anlutro-l4-validation/feed)WikiDiscussions master Synced 2d ago

READMEChangelogDependencies (3)Versions (22)Used By (1)

Laravel 4 Validation [![Build Status](https://camo.githubusercontent.com/49697b421781e276dc34f8c7f9a90983dd429fdbb3ea5028bb656d66827c442e/68747470733a2f2f7472617669732d63692e6f72672f616e6c7574726f2f6c61726176656c2d76616c69646174696f6e2e706e673f6272616e63683d6d6173746572)](https://travis-ci.org/anlutro/laravel-validation) [![Latest Version](https://camo.githubusercontent.com/c0becb37b3e20b05d6cfd56a89819d70990299bbb02412eb5c4256061c187e47/687474703a2f2f696d672e736869656c64732e696f2f6769746875622f7461672f616e6c7574726f2f6c61726176656c2d76616c69646174696f6e2e737667)](https://github.com/anlutro/laravel-validation/releases)
==================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================================

[](#laravel-4-validation--)

Installation: `composer require anlutro/l4-validation`

Pick the latest stable version from packagist or the GitHub tag list.

WARNING: Backwards compatibility is not guaranteed during version 0.x.

### Validation service

[](#validation-service)

This validation class is a layer on top of Laravel's own Validation class (the one you create by calling Validator::make), meant to be injected into a repository or controller. It allows for more advanced rulesets and more dynamic rules, and is being utilized in my [repository class](https://github.com/anlutro/laravel-repository).

Your class must implement one abstract method: `getCommonRules`. This should return an array of rules that are used on every validation call and should be the bare minimum of rules. In addition you can implement as many extra rule getters as you like - `getCreateRules`, `getUpdateRules`, `getUpdateAsAdminRules`, `getFooRules` and so on.

Rules are dynamically merged depending on what action you're trying to validate. For example, `$validator->validCreate($attributes)` will merge `getCommonRules` and `getCreateRules`. If `getCreateRules` doesn't exist, it'll just use `getCommonRules`. `$validator->validUpdateAsAdmin($attributes)` will merge `getCommonRules` and `getUpdateAsAdminRules`. Rules are merged recursively.

You can tell the validator to replace variables in rules with the `replace($key, $value)` method. For example, if you have a unique rule and want to dynamically replace the table with a model's table, you can do the following:

```
public function getCommonRules() {
	return ['email' => 'unique:'];
}

$validator->replace('table', $model->getTable());

```

The class will also replace variables in square brackets with the matching key from input. For example, `[foo]` will be replaced with whatever the value of 'foo' from the provided input (attributes) are. This way, you can add the value of another input field to a rule (for example, `'end_date' => ['date', 'after:[start_date]']`.

Replacing variables will not work in regex rules, as that would potentially break regex operators.

There are a couple of hooks you can use to add custom behaviour. `prepareRules($rules, $attributes)` will be called after rules are merged and allows you to change validation rules based on input if necessary. This method *needs* to return the modified array of rules!

`prepareValidator($validator)` is called before checking if validation passes or not, and can be used to add sometimes() rules or any other custom behaviour onto the Illuminate\\Validation\\Validator object itself.

#### Exceptions

[](#exceptions)

You can call `$validatorService->toggleExceptions();` to make the validator throw exceptions instead of just returning false. The exception thrown will be of the type `anlutro\LaravelValidation\ValidationException`, which has some useful methods.

- `getErrors()` gets a flat array of the validation errors.
- `getRules()` gets the array of rules that were used when validating.
- `getAttributes()` gets the array of input that was validated.

It can also be cast to a string via `(string) $exception` which will render each validation error on one line.

Contact
-------

[](#contact)

Open an issue on GitHub if you have any problems or suggestions.

License
-------

[](#license)

The contents of this repository is released under the [MIT license](http://opensource.org/licenses/MIT).

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity27

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity57

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 ~21 days

Recently: every ~79 days

Total

19

Last Release

4115d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/48f62855097c02888b96494da9a389988cd7ecb9001465f8ec30f15672fb5b5a?d=identicon)[anlutro](/maintainers/anlutro)

---

Top Contributors

[![anlutro](https://avatars.githubusercontent.com/u/163093?v=4)](https://github.com/anlutro "anlutro (41 commits)")

### Embed Badge

![Health badge](/badges/anlutro-l4-validation/health.svg)

```
[![Health](https://phpackages.com/badges/anlutro-l4-validation/health.svg)](https://phpackages.com/packages/anlutro-l4-validation)
```

###  Alternatives

[propaganistas/laravel-phone

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

3.0k35.7M107](/packages/propaganistas-laravel-phone)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[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)[sunspikes/clamav-validator

Custom Laravel 5 anti-virus validator for file uploads.

3651.8M3](/packages/sunspikes-clamav-validator)

PHPackages © 2026

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