laravel/framework — pull request #739 by KaneCohen (2013-03-28 10:36:04+00:00)
Title: Add ability to validate arrays explicitly

Ok, this is a for of my other PR (#255) related to Validator.

This PR introduces additional special characters: "[]". Square brackets now are going to be an indicator that certain attribute must be validated as an array of items. And works like that:

````php
$input = array('tags' => array('foo', 'bar', 'baz'));

$val = Validator::make($input, array('tags[]' => 'required|alpha'));
````

As you can see, we have an attribute `tags[]` in the rules set. What it does, is it tells to the Validator that `tags` attribute is an array and each of it's items have to be validated against "required" and "alpha" rules.

But what if we didn't specify that `tags` is an array?
````php
$val = Validator::make($input, array('tags' => 'required|alpha'));
````

We'll get an exception.

-------

Now, one important not related to array validation with `exists` rule?

````php
$input = array('tags' => array('foo', 'bar', 'baz'));

$val = Validator::make($input, array('tags[]' => 'exists:tags_table,name'));
// In this scenario Validator will go through every item in the array chacking it agains the DB.

$val = Validator::make($input, array('tags' => 'exists:tags_table,name'));
// In this scenario Validator will make only one query with "WHERE IN" clause
````

Also, now you can mix rules:
````php
$input = array('tags' => array('foo', 'bar', 'baz'));

$val = Validator::make($input, array(
'tags[]' => 'required|alpha'
'tags' => 'exists:tags_table,name'
));
````
As you can see, you can use `tags[]` to validate every item in the array against certain rules, while you can also have `tags` checking certain rules (exists) over the array as a whole.

P.S.: I'm not adding extra commit here, but i'm wondering if `getSize` method should return array length if value is an array. I guess that's for the Issue or another PR.