-
Notifications
You must be signed in to change notification settings - Fork 11.4k
Make arrays and its contents validatable #255
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
I believe you can validate nested fields with the array dot syntax: |
This PR allows for validating |
@franzliedke, i don't believe so since if (array_key_exists($attribute, $this->data))
{
return $this->data[$attribute];
}
elseif (array_key_exists($attribute, $this->files))
{
return $this->files[$attribute];
} But even if that was a case, it's still only one element out of the array that might have an unknown size. Sure, you might generate rules based on the length of the input array, but that seems like an unnecessary hacking. |
Ah, okay. Thanks for clarifying and sorry for not double-checking, guys. |
Fix validateExists to work with arrays as a whole Swap if/else in validateSame/Different
+1 on this. |
+1 |
@KaneCohen Using the above, how are custom error messages handled? The same way? |
@scbenjamin, yes, the same way. Taking example above: $input = array('tags' => array(
'new' => array('foo', 'bar1', 'baz'),
));
$val = Validator::make($input, array('tags.new' => 'required|alpha')); Validation will fail because validation.php file for language: 'custom' => array(
'tags.new.alpha' => 'Tags may contain only alphabetical characters.'
), |
👍 |
For the |
@taylorotwell, hmm, yeah. It seems like that thing ( |
Fix File uploads because blob size was not big enough; Fixes laravel#253
Currently, there's no way to validate contents of input arrays. This pull request tries to fix that.
Example:
will send to PHP following array:
Right now there's no way to check whole array for a certain rules, like alpha/numeric etc. However, with this patch you can validate
tags
array like so:Validator will determine that
tags
key refers to the array and will proceed to validate each element according to set rulesrequired|alpha
;This patch also allows to use dot notation to validate inner arrays of other arrays:
In this case Validator will validate
new
array that is inside of thetags
array.P.S.: Some of the test were omitted because of a similarities with other tests.