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

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

hocvt/laravel-validation
========================

Laravel Validation Service

v6.0.1(6y ago)08361PHPPHP &gt;=7.2

Since Jan 26Pushed 6y agoCompare

[ Source](https://github.com/vuthaihoc/laravel-validator)[ Packagist](https://packagist.org/packages/hocvt/laravel-validation)[ Docs](http://andersao.github.io/laravel-validation)[ RSS](/packages/hocvt-laravel-validation/feed)WikiDiscussions master Synced 2mo ago

READMEChangelog (2)Dependencies (2)Versions (11)Used By (1)

Laravel Validation Service
==========================

[](#laravel-validation-service)

[![Total Downloads](https://camo.githubusercontent.com/0f252024417a63c2cb3d7952113ca6122f6eb30849d77a42b6d9671a7effefa6/68747470733a2f2f706f7365722e707567782e6f72672f707265747475732f6c61726176656c2d76616c69646174696f6e2f646f776e6c6f6164732e737667)](https://packagist.org/packages/prettus/laravel-validation)[![Latest Stable Version](https://camo.githubusercontent.com/5a58e04fc9e1c5329c8966d3a7aa64d1eb7891fab0c916800e41d27f5786812f/68747470733a2f2f706f7365722e707567782e6f72672f707265747475732f6c61726176656c2d76616c69646174696f6e2f762f737461626c652e737667)](https://packagist.org/packages/prettus/laravel-validation)[![Latest Unstable Version](https://camo.githubusercontent.com/ea4e13289509c7bab8ab905aeff89903dd344b7c41e8220ccda2d058bcba7c4f/68747470733a2f2f706f7365722e707567782e6f72672f707265747475732f6c61726176656c2d76616c69646174696f6e2f762f756e737461626c652e737667)](https://packagist.org/packages/prettus/laravel-validation)[![License](https://camo.githubusercontent.com/c47050b9e7e2815d29279f34b9dbb78a5c0e5365362cfb923389d7c1fba4b955/68747470733a2f2f706f7365722e707567782e6f72672f707265747475732f6c61726176656c2d76616c69646174696f6e2f6c6963656e73652e737667)](https://packagist.org/packages/prettus/laravel-validation)

Installation
------------

[](#installation)

Add "prettus/laravel-repository": "1.1.\*" to composer.json

```
"prettus/laravel-validation": "1.1.*"
```

### Create a validator

[](#create-a-validator)

The Validator contains rules for adding, editing.

```
Prettus\Validator\Contracts\ValidatorInterface::RULE_CREATE
Prettus\Validator\Contracts\ValidatorInterface::RULE_UPDATE
```

In the example below, we define some rules for both creation and edition

```
use \Prettus\Validator\LaravelValidator;

class PostValidator extends LaravelValidator {

    protected $rules = [
        'title' => 'required',
        'text'  => 'min:3',
        'author'=> 'required'
    ];

}
```

To define specific rules, proceed as shown below:

```
use \Prettus\Validator\LaravelValidator;

class PostValidator extends LaravelValidator {

    protected $rules = [
        ValidatorInterface::RULE_CREATE => [
            'title' => 'required',
            'text'  => 'min:3',
            'author'=> 'required'
        ],
        ValidatorInterface::RULE_UPDATE => [
            'title' => 'required'
        ]
   ];

}
```

### Custom Error Messages

[](#custom-error-messages)

You may use custom error messages for validation instead of the defaults

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

Or, you may wish to specify a custom error messages only for a specific field.

```
protected $messages = [
    'email.required' => 'We need to know your e-mail address!',
];
```

### Custom Attributes

[](#custom-attributes)

You too may use custom name attributes

```
protected $attributes = [
    'email' => 'E-mail',
    'obs' => 'Observation',
];
```

### Using the Validator

[](#using-the-validator)

```
use \Prettus\Validator\Exceptions\ValidatorException;

class PostsController extends BaseController {

    /**
     * @var PostRepository
     */
    protected $repository;

    /**
     * @var PostValidator
     */
    protected $validator;

    public function __construct(PostRepository $repository, PostValidator $validator){
        $this->repository = $repository;
        $this->validator  = $validator;
    }

    public function store()
    {

        try {

            $this->validator->with( Input::all() )->passesOrFail();

            // OR $this->validator->with( Input::all() )->passesOrFail( ValidatorInterface::RULE_CREATE );

            $post = $this->repository->create( Input::all() );

            return Response::json([
                'message'=>'Post created',
                'data'   =>$post->toArray()
            ]);

        } catch (ValidatorException $e) {

            return Response::json([
                'error'   =>true,
                'message' =>$e->getMessage()
            ]);

        }
    }

    public function update($id)
    {

        try{

            $this->validator->with( Input::all() )->passesOrFail( ValidatorInterface::RULE_UPDATE );

            $post = $this->repository->update( Input::all(), $id );

            return Response::json([
                'message'=>'Post created',
                'data'   =>$post->toArray()
            ]);

        }catch (ValidatorException $e){

            return Response::json([
                'error'   =>true,
                'message' =>$e->getMessage()
            ]);

        }

    }
}
```

Author
======

[](#author)

Anderson Andrade -

Credits
-------

[](#credits)

###  Health Score

31

—

LowBetter than 68% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity14

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 66.7% 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 ~216 days

Recently: every ~415 days

Total

9

Last Release

2389d ago

Major Versions

1.1.5 → v6.0.02019-09-05

PHP version history (2 changes)1.0.0PHP &gt;=5.4.0

v6.0.0PHP &gt;=7.2

### Community

Maintainers

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

---

Top Contributors

[![andersao](https://avatars.githubusercontent.com/u/1131667?v=4)](https://github.com/andersao "andersao (20 commits)")[![jartaud](https://avatars.githubusercontent.com/u/266818?v=4)](https://github.com/jartaud "jartaud (3 commits)")[![mapb1990](https://avatars.githubusercontent.com/u/1731701?v=4)](https://github.com/mapb1990 "mapb1990 (2 commits)")[![moura137](https://avatars.githubusercontent.com/u/1171111?v=4)](https://github.com/moura137 "moura137 (2 commits)")[![vuthaihoc](https://avatars.githubusercontent.com/u/2509658?v=4)](https://github.com/vuthaihoc "vuthaihoc (2 commits)")[![henninghorn](https://avatars.githubusercontent.com/u/742607?v=4)](https://github.com/henninghorn "henninghorn (1 commits)")

---

Tags

laravelvalidationservice

### Embed Badge

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

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

###  Alternatives

[propaganistas/laravel-phone

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

3.0k35.7M106](/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)[prettus/laravel-validation

Laravel Validation Service

40710.8M51](/packages/prettus-laravel-validation)[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)[laravel-validation-rules/credit-card

Validate credit card number, expiration date, cvc

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

PHPackages © 2026

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