KaneCohen / laravel-validation by KaneCohen

Extra functionality for Laravel 4 Validator.
13,924
15
2
Package Data
Maintainer Username: KaneCohen
Maintainer Contact: kanecohen@gmail.com (Kane Cohen)
Package Create Date: 2013-08-13
Package Last Update: 2016-04-05
Language: PHP
License: BSD-3-Clause
Last Refreshed: 2024-11-14 15:08:04
Package Statistics
Total Downloads: 13,924
Monthly Downloads: 3
Daily Downloads: 0
Total Stars: 15
Total Watchers: 2
Total Forks: 3
Total Open Issues: 1

Extended Laravel Validation

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);