PHPackages                             kohkimakimoto/laravel-validator-extension - 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. kohkimakimoto/laravel-validator-extension

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

kohkimakimoto/laravel-validator-extension
=========================================

An extension for Laravel4 validator.

v0.3.0(11y ago)4237MITPHPPHP &gt;=5.4.0

Since Aug 15Pushed 11y ago1 watchersCompare

[ Source](https://github.com/kohkimakimoto/LaravelValidatorExtension)[ Packagist](https://packagist.org/packages/kohkimakimoto/laravel-validator-extension)[ RSS](/packages/kohkimakimoto-laravel-validator-extension/feed)WikiDiscussions master Synced 3d ago

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

Laravel Validator Extension
===========================

[](#laravel-validator-extension)

[![Build Status](https://camo.githubusercontent.com/3b12067d18fa45ea00b274e2fb9f60a94eb53de19d8cbf929fb5fa266a883263/68747470733a2f2f7472617669732d63692e6f72672f6b6f686b696d616b696d6f746f2f4c61726176656c56616c696461746f72457874656e73696f6e2e7376673f6272616e63683d6d6173746572)](https://travis-ci.org/kohkimakimoto/LaravelValidatorExtension)[![Coverage Status](https://camo.githubusercontent.com/3cb857f0ded339f02ff3249c14dc6170a452ea5d66b6a9fa0141698776b392a2/68747470733a2f2f636f766572616c6c732e696f2f7265706f732f6b6f686b696d616b696d6f746f2f4c61726176656c56616c696461746f72457874656e73696f6e2f62616467652e706e673f6272616e63683d6d6173746572)](https://coveralls.io/r/kohkimakimoto/LaravelValidatorExtension?branch=master)

An extension for [Laravel4](http://laravel.com/) validator.

- Support to define validation rules in a specific class.
- Provide another syntax to define validation rules.
- Filter input values before and after validation.

Look at [usage](#usage) to get more detail.

Installation
============

[](#installation)

Add dependency in `composer.json`

```
"require": {
    "kohkimakimoto/laravel-validator-extension": "0.*"
}
```

Run `composer upadte` command.

```
$ composer update

```

Add `ValidatorExtensionServiceProvider` provider to `providers` configuration in `app/config/app.php`.

```
'providers' => array(
    ....
    'Kohkimakimoto\ValidatorExtension\ValidatorExtensionServiceProvider',
}

```

Add `BaseValidator` alias to `aliases` configuration in `app/config/app.php`.

```
'aliases' => array(
    ...
    'BaseValidator' => 'Kohkimakimoto\ValidatorExtension\Validator',
),
```

Add a path to laravel class loader in `app/start/global.php`.

```
ClassLoader::addDirectories(array(
    ...
    app_path().'/validators',
));
```

And add a path at `autoload` section in `composer.json`.

```
"autoload": {
    "classmap": [
        ...
        "app/validators"
    ]
}
```

Usage
-----

[](#usage)

- [Define validation rules](#define-validation-rules)
- [Filters](#filters)
- [Custom validation rules](#custom-validation-rules)
- [Custom methods](#custom-methods)

### Define validation rules

[](#define-validation-rules)

You can define validation rules in a validator class. If you added a path to autoload and class loader configuration at the installation steps, you can define the validator class in the `app/validators` directory.

```
// app/validators/BlogValidator.php
class BlogValidator extends BaseValidator
{
    protected function configure()
    {
        $this
            ->rule('title', 'required', 'Title is required.')
            ->rule('title', 'max:100', 'Title must not be greater than 100 characters.')
            ->rule('body', 'pass')
            ;
    }
}
```

You can use `$this->rule` method to add a validation rule. The third argument is optional to customize a error message.

The validator class is used as the below.

```
$validator = BlogValidator::make(Input::all());
if ($validator->fails()) {
    return Redirect::back()->withInput(Input::all())->withErrors($validator);
}

// Get only validated data.
$data = $validator->onlyValidData();
```

### Filters

[](#filters)

You can filter input values before and after validation.

```
class BlogValidator extends BaseValidator
{
    protected function configure()
    {
        $this->beforeFilter(function($validator){
            // your code
        });

        $this->afterFilter(function($validator){
            // Modify title after validation.
            $title = $validator->title;
            $title .= " created by kohki";
            $validator->title = $title;
        });
    }
}
```

### Custom validation rules

[](#custom-validation-rules)

You can define custom validation rules in the class.

```
class BlogValidator extends BaseValidator
{
    protected function configure()
    {
        $this
            ->rule('title', 'required', 'Title is required.')
            ->rule('title', 'max:100', 'Title must not be greater than 100 characters.')
            ->rule('body', 'foo', 'Body must be foo only!')
            ;
    }

    protected function validateFoo($attribute, $value, $parameters)
    {
        return $value == 'foo';
    }
}
```

### Custom methods

[](#custom-methods)

The validator can be used as a value object. So you can append some custom methods to manipulate data stored in it.

```
class BlogValidator extends BaseValidator
{
    public function getTitleOrDefault() {
        if ($this->title === null) {
            return "Default title";
        } else {
            return $this->title;
        }
    }
}
```

LICENSE
-------

[](#license)

The MIT License

Author
------

[](#author)

Kohki Makimoto

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity15

Limited adoption so far

Community7

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

Total

3

Last Release

4287d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/232e612dbf32e70978372a2249e28dd037f75eadafc547913375708571c65f9a?d=identicon)[kohkimakimoto](/maintainers/kohkimakimoto)

---

Top Contributors

[![kohkimakimoto](https://avatars.githubusercontent.com/u/761462?v=4)](https://github.com/kohkimakimoto "kohkimakimoto (43 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/kohkimakimoto-laravel-validator-extension/health.svg)

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

###  Alternatives

[propaganistas/laravel-phone

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

3.0k35.7M107](/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)[spatie/laravel-honeypot

Preventing spam submitted through forms

1.6k6.0M60](/packages/spatie-laravel-honeypot)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

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

The Illuminate Validation package.

18936.7M1.4k](/packages/illuminate-validation)[axlon/laravel-postal-code-validation

Worldwide postal code validation for Laravel and Lumen

3853.3M1](/packages/axlon-laravel-postal-code-validation)

PHPackages © 2026

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