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

AbandonedArchivedLibrary

experience/validation
=====================

Easy data validation, with support for separate 'create' and 'update' rulesets.

1.0.3(11y ago)03861MITPHPPHP &gt;=5.4.0

Since Jun 28Pushed 11y ago1 watchersCompare

[ Source](https://github.com/experience/laravel4-validation)[ Packagist](https://packagist.org/packages/experience/validation)[ RSS](/packages/experience-validation/feed)WikiDiscussions master Synced 5d ago

READMEChangelogDependencies (2)Versions (5)Used By (1)

 [![](https://camo.githubusercontent.com/74d6abef27c60755543271e7e8c955384f6cc08d8f80d6d893f6b4755f965c1a/68747470733a2f2f7472617669732d63692e6f72672f657870657269656e63652f56616c69646174696f6e2e737667 "Build Status Images")](https://camo.githubusercontent.com/74d6abef27c60755543271e7e8c955384f6cc08d8f80d6d893f6b4755f965c1a/68747470733a2f2f7472617669732d63692e6f72672f657870657269656e63652f56616c69646174696f6e2e737667)

Overview
--------

[](#overview)

This package makes it easy to implement custom validation for any given array of data in your application. It also solves a common problem whereby the validation rules for a "create" action differ to those for an "update" action.

For example, let's say we need to validate some "user account" data, both at the point of registration, and if the user chooses to modify their account at a later date. In Laravel, our (partial) validation rules might look something like this:

```
$rules = ['username' => 'required|unique:users'];
```

That is, the value of the `username` field must be unique within the `users` table.

This is fine for account creation, but if the user updates his account without changing his username, the above validation rules will fail. The current `users` table already contains the given username, and the validation rules don't care that it belongs to the user being validated.

In Laravel, we deal with this problem by telling the validator to ignore the `id` of the current user, so our rules now look like this:

```
// The user ID is 1234.
$rules = ['username' => 'required|unique:users,null,1234'];
```

The Validation package solves this problem by separating the "create" and "update" validation rules, and allowing you to use a `{key}` placeholder in your rules. Continuing with the above example, our validation rules now look like this:

```
$createRules = ['username' => 'required|unique:users'];
$updateRules = ['username' => 'required|unique:users,null,{key}'];
```

More detailed implementation examples are provided in the "Usage" section, below.

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

[](#installation)

Install the package via [Composer](http://getcomposer.org/), as follows:

```
"require": {
    "experience/validation": "~1.0"
}
```

If you're using Laravel, add the service provider to the `providers` array in your `app/config/app.php` file, as follows:

```
'providers' => [
    // ...
    'Experience\Validation\ValidationServiceProvider',
];
```

Usage
-----

[](#usage)

Let's assume you need to validate a registration form. First, create a custom "validator" class containing the necessary "create" and "update" rules. For example:

```
