PHPackages                             two-bros/validation-service - 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. two-bros/validation-service

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

two-bros/validation-service
===========================

1.08(10y ago)117Apache-2.0PHP

Since Sep 3Pushed 10y ago1 watchersCompare

[ Source](https://github.com/2brosdevelopment/validation-service)[ Packagist](https://packagist.org/packages/two-bros/validation-service)[ RSS](/packages/two-bros-validation-service/feed)WikiDiscussions develop Synced yesterday

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

Installation &amp; Setup [![Build Status](https://camo.githubusercontent.com/b7dbff48557a2de0bced21f447d012170ecdc77a652c96a48e2aeb2d378dbeae/68747470733a2f2f7472617669732d63692e6f72672f3262726f73646576656c6f706d656e742f76616c69646174696f6e2d736572766963652e7376673f6272616e63683d646576656c6f70)](https://travis-ci.org/2brosdevelopment/validation-service)
===================================================================================================================================================================================================================================================================================================================================================================

[](#installation--setup-)

Composer
--------

[](#composer)

You can install this package via [Composer](http://getcomposer.org) by running the command: `composer require "two_bros/validation-service:~1.0"`.

Or by adding the package to your `composer.json`

```
    {
        "require": {
            "two_bros/validation-service": "~1.0"
        }
    }
```

Then install it via `composer install` or `composer update`

Configuration
-------------

[](#configuration)

Once you have installed the package, you will need to register the Service Provider in your `config/app.php` under the `providers` array:

```
    'providers' => [
        ...
        TwoBros\ValidationService\Providers\ValidationServiceProvider::class,
    ];
```

After adding the Service Provider to your `config/app.php`, you should publish the configuration from the package using: `php artisan vendor:publish`

This will create a file named `validation_service.php` in the configuration directory. This file will be utilized to add any custom validation rules you may create.

The format for this configuration file is:

```
    return [
        'passwordStrength' => 'User@passwordStrength'
    ];
```

Basic Usage
===========

[](#basic-usage)

Simple Validation
-----------------

[](#simple-validation)

For each model that you need to validate, you can simply create a validation class and extend the `TwoBros\ValidationService\Services\Validation\LaravelValidator`.

```
    use TwoBros\ValidationService\Services\Validation\LaravelValidator;

    class ModelCreateValidator extends LaravelValidator
    {
        protected $rules = [
            'name' => 'required|min:8'
        ];

    }
```

Now when you want to validate data, you can pass the data into the validator and determine if it passed or not.

```
    $modelValidator = new ModelCreateValidator($this->app['validator']);

    if ($modelValidator->with($inputArray)
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();

        // Do some stuff for failing
    }
```

Custom Messages
---------------

[](#custom-messages)

If you want customize your validation messages, you can do this by passing the message array to the `with` method.

```
    $messages = [
        'required' => 'The field :attribute is required'
    ];

    $modelValidator = new ModelCreateValidator($this->app['validator']);

    if ($modelValidator->with($inputArray, $messages)
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();

        // Do some stuff for failing
    }
```

Or by using the `withMessages` method of the validator.

```
    $messages = [
        'required' => 'The field :attribute is required'
    ];

    $modelValidator = new ModelCreateValidator($this->app['validator']);

    if ($modelValidator->with($inputArray)
                       ->withMessages($messages)
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();

        // Do some stuff for failing
    }
```

Adding Uniqueness Requirements to Validation
--------------------------------------------

[](#adding-uniqueness-requirements-to-validation)

There are times when you may want to use uniqueness, but when you are doing an update you need to use the id of current record to exclude the current record from the uniqueness check.

For this, you need to add a method to your validator class `addRuntimeValidationRules` that updates the rules with the ids needed.

```
    use TwoBros\ValidationService\Services\Validation\LaravelValidator;

    class ModelCreateValidator extends LaravelValidator
    {
        protected $rules = [
            'name' => 'required|min:8',
            'email' => 'required|max:100|unique:users,email'
        ];

        public function addRuntimeValidationRules()
        {

            $this->rules[ 'email' ] = 'required|max:100|unique:users,email,' . $this->uniqueIds[ 'email' ];

            return $this;
        }
    }
```

You can then add the function to the call string, so you can customize this with the id needed upon validation.

```
    $modelValidator = new ModelCreateValidator($this->app['validator']);

    if ($modelValidator->with($inputArray)
                       ->setUniqueId('email', $modelToUpdate->id)
                       ->addRuntimeValidationRules()
                       ->passes()) {
        // Do some stuff for passing
    } else {
        // Get the errors
        $validationErrors = $modelValidator->errors();

        // Do some stuff for failing
    }
```

You will note that you must use the `setUniqueId` method call to set the id of the current record. Also, instead of instantiating the validator class, you can use Laravel's IoC to bring it into the method.

```
    public function update(ModelValidator $modelValidator) {

        if ($modelValidator->with($inputArray)
                           ->setUniqueId('email', $modelToUpdate->id)
                           ->addRuntimeValidationRules()
                           ->passes()) {
            // Do some stuff for passing
        } else {
            // Get the errors
            $validationErrors = $modelValidator->errors();

            // Do some stuff for failing
        }

    }
```

License
=======

[](#license)

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

```
http://www.apache.org/licenses/LICENSE-2.0

```

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

###  Health Score

29

—

LowBetter than 57% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity7

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity69

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

Total

9

Last Release

3952d ago

### Community

Maintainers

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

---

Top Contributors

[![vsposato](https://avatars.githubusercontent.com/u/894126?v=4)](https://github.com/vsposato "vsposato (36 commits)")

---

Tags

laravelvalidation

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/two-bros-validation-service/health.svg)

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

###  Alternatives

[schuppo/password-strength

This package provides a validator for ensuring strong passwords in Laravel 4 applications.

1442.8M1](/packages/schuppo-password-strength)[timacdonald/rule-builder

A fluent rule builder for Laravel validation rule generation.

1027.9k](/packages/timacdonald-rule-builder)[stuyam/laravel-phone-validator

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

2861.9k](/packages/stuyam-laravel-phone-validator)[skysplit/laravel5-intl-translation

Laravel 5 package for better translation syntax using php-intl extension

10106.6k](/packages/skysplit-laravel5-intl-translation)[pacerit/laravel-polish-validation-rules

Simple Polish Validation rules for Laravel and Lumen framework

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

Validate if an ip address is public or private.

1629.7k](/packages/laravel-validation-rules-ip)

PHPackages © 2026

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