cohensive/validation

Extra functionality for Laravel 5 Validator.

v5.0.0 2015-02-16 13:02 UTC

This package is auto-updated.

Last update: 2021-10-08 00:49:39 UTC


README

This class extends Laravel Validation package changing some basic functionality to provide validation of data with wildcards. How do wildcrads work:

wildcrads

Installation

Add following line to your composer.json file:

For Laravel 4.x

"cohensive/validation": "4.1.*"

For Laravel 5.x

"cohensive/validation": "5.0.*"

Then run composer install or composer update to download it and autoload.

Once package is installed you need to register it as a service provider. Find app.php file in your config deirectory. First, since this package extends default Validation, you need to comment out or remove this line from providers array: 'Illuminate\Validation\ValidationServiceProvider'.

Now in the same providers array you need to add new package:

'providers' => array(

    //...
    'Cohensive\Validation\ValidationServiceProvider',
    //...

)

No need to add anything in aliases.

Usage

Mostly the same as in core Validation. When it comes to validation with wildcrads here's an example:

$input = array('input' => array('foo', 'bar', 'baz'));
$rules = array(
    'input:*' => 'Alpha|Min:3'
);

$v = Validator::make($input, $rules);

Shall we go deeper?

$input = array('users' => array(
    0 => array(
        'name' => 'Mike',
        'age'  =>  30
    ),
    1 => array(
        'name' => 'Rob',
        'age'  => '28'
    )
));

$rules = array(
    'users:*:name' => 'Alpha|Min:3',
    'users:*:age'  => 'Numeric|Min:18|Max:80'
);

$v = Validator::make($input, $rules);