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

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

browner12/validation
====================

validation package for use in Laravel projects

v2.1.0(6y ago)11.1k1MITPHPPHP ^7.2

Since Feb 20Pushed 6y ago1 watchersCompare

[ Source](https://github.com/browner12/validation)[ Packagist](https://packagist.org/packages/browner12/validation)[ Docs](https://github.com/browner12/validation)[ RSS](/packages/browner12-validation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (3)Dependencies (5)Versions (4)Used By (0)

Validation
==========

[](#validation)

[![Latest Version on Packagist](https://camo.githubusercontent.com/301d62f5fe3fdfe2fd2ee6931b3ef6597da9e66435d0d83122b0137d63243359/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f62726f776e657231322f76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/browner12/validation)[![Software License](https://camo.githubusercontent.com/55c0218c8f8009f06ad4ddae837ddd05301481fcf0dff8e0ed9dadda8780713e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4d49542d627269676874677265656e2e7376673f7374796c653d666c61742d737175617265)](LICENSE.md)[![Build Status](https://camo.githubusercontent.com/8ec9a0f5b6a24d344c665163af2e565eec654555f63727f3bb0aeb3b82e27ab9/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f62726f776e657231322f76616c69646174696f6e2f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/browner12/validation)[![Coverage Status](https://camo.githubusercontent.com/0fb264ae8e45ec7545d69b6379c9635a77a55956106c6d0b593e63c21283d18b/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f636f7665726167652f672f62726f776e657231322f76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/browner12/validation/code-structure)[![Quality Score](https://camo.githubusercontent.com/aab7826327bc4efac3186ef33fbfc7eef8f7689066bbe5c0649442945b90ef8a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f62726f776e657231322f76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/browner12/validation)[![Total Downloads](https://camo.githubusercontent.com/2988152950b0328adfb25571a37b0cb5b911d1b733d37481906aa52dd9063a66/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f62726f776e657231322f76616c69646174696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/browner12/validation)

This is a validation package built to complement Laravel's included validation. One of the main benefits of this package is a separate file houses the reusable rules for validation.

Install
-------

[](#install)

```
$ composer require browner12/validation
```

Setup
-----

[](#setup)

Add the service provider to the providers array in `config/app.php`.

```
'providers' => [
    browner12\validation\ValidationServiceProvider::class,
];
```

Usage
-----

[](#usage)

Use Artisan to generate a new validator.

```
php artisan make:validator UserValidator
```

Validators extend the abstract `browner12\validation\Validator`, which contains all of the methods necessary to perform validation. The only thing you need to define are your rules. For example, if you have a 'Product' model, you could create a `ProductValidator`. While they *can* be placed anywhere that can be autoloaded, a good suggestion is `app/Validation`.

```
namespace App\Validation;

class ProductValidator extends Validator
{
    protected static $store = [
        'name'  => 'required',
        'price' => 'required|int',
    ];

    protected static $update = [
        'name'  => 'required',
        'price' => 'required|int',
    ];
}
```

As you can see, validators can contain multiple rule sets. To use the validator, create a new `Validator` object, or use dependency injection (DI is used in the example). Pass in the data to be validated and the name of the rule set to use. A good place to handle the validation is in a dedicated class (sometimes referred to as a Service) so it can be reused throughout the site.

```
namespace App\Services;

use App\Validation\ProductValidator;
use browner12\validation\ValidationException;

class ProductService
{
    /**
     * constructor
     *
     * @param \App\Validation\ProductValidator $validator
     */
    public function __construct(ProductValidator $validator)
    {
        $this->validator = $validator;
    }

    /**
     * store product
     *
     * @param array $input
     * @throws \browner12\validation\ValidationException
     */
    public function store(array $input)
    {
        if ($this->validator->isValid($input, 'store')) {

            //data is good, save to storage
            return true;
        }

        throw new ValidationException('Storing a product failed.', $this->validator->getErrors());
    }
}
```

Finally, your controller will call the service, and handle any errors that are thrown.

```
use App\Services\ProductService;
use browner12\validation\ValidationException;

class ProductController
{
    /**
     * constructor
     */
    public function __construct(ProductService $service)
    {
        $this->service = $service;
    }

    /**
     * store
     */
    public function store()
    {
        try {

            $data = [
                'name'  => $_POST['name'],
                'price' => $_POST['price'],
            ];

            $this->service->store($data);
        }

        catch (ValidationException $e){

            //handle the exception
        }
    }
}
```

Changelog
---------

[](#changelog)

Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.

Testing
-------

[](#testing)

```
$ composer test
```

Contributing
------------

[](#contributing)

Please see [CONTRIBUTING](CONTRIBUTING.md) and [CONDUCT](CONDUCT.md) for details.

Security
--------

[](#security)

If you discover any security related issues, please email  instead of using the issue tracker.

Credits
-------

[](#credits)

- [Andrew Brown](https://github.com/browner12)
- [All Contributors](../../contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

29

—

LowBetter than 59% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity17

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

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

Total

3

Last Release

2258d ago

Major Versions

v1.0.0 → v2.0.02019-09-09

PHP version history (2 changes)v1.0.0PHP &gt;=5.6.0

v2.0.0PHP ^7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/fa26eb2ff60e4c5077e691d2b0b83bd76051e22a8b26329f873017dc8e8d1b03?d=identicon)[browner12](/maintainers/browner12)

---

Top Contributors

[![browner12](https://avatars.githubusercontent.com/u/5232313?v=4)](https://github.com/browner12 "browner12 (33 commits)")

---

Tags

laravelphpvalidationbrowner12

###  Code Quality

TestsPHPUnit

Code StylePHP\_CodeSniffer

### Embed Badge

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

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

###  Alternatives

[propaganistas/laravel-phone

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

3.0k35.7M107](/packages/propaganistas-laravel-phone)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[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)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)

PHPackages © 2026

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