Open LKay opened 8 years ago
Would it just check the type of each element in the array, so you could see if the array contained strings, objects, etc?
Basically yes. The idea is to be able to validate array elements.
Use case: I want to pass an array which contains strings with length of at least 3 characters.
Seems like this would be better as a custom rule since it seems very specific. Plus, if we did add it, to what degree would it be? Validating the array's element types? Validating the structure or contents of the array's elements? Does Laravel do something like this? What do you think @garygreen?
The idea is to validate just array contents and not structure. I imagine that would iterate over array elements and run validation for each.
Laravel doesn't do that and requires to write validation for array manually according to docs. Maybe it's indeed a better idea to create another rule and leave array
as it is. Yet I think it's pretty common case when you want to validate array contents.
What do you think about having a core validatorjs containing the same set of rules ad Laravel and separate plugin-like package with additional rules that Laravel doesn't have?
Laravel doesn't do that and requires to write validation for array manually according to docs.
Laravel does have array wildcard validation, older versions of Laravel used the each
rule/function. I think we should support wildcards.
Supporting wild cards for array sounds like a better solution and it would be the same as Laravel handling such cases. For that purpose maybe we also should abandon support for defining rules as nested object and just support flat structure to be more compliant with original library?
I don't think Laravel supports nested rules? Would make more sense to support wildcards instead.
Im looking at the Laravel Validator docs for the array rule and I don't see anything about wildcards. Is it located somewhere else?
I'm looking at this documentation.
https://laravel.com/docs/5.2/validation#validating-arrays
Note the use of wild cards in the email and first_name properties.
Ah I see it. I don't have time to add this, but if someone wants to add this feature, please do!
I implemented it last night. I have a little more testing to do and then I'll send a pull request. I also have a few updated to the readme I want to send.
awesome, thanks!
@bricox @skaterdav85 Hi i read that, is amazing, is now implemented? or yet help with that? thanks !!
Hi guys, any update for validating arrays? I'd use this feature in my project.
@bricox you still working on this? If not, @mikeerickson, want to help out with this?
@skaterdav85 Sure thing, I will tackle it next
@bricox Seeing as you have already implemented, no sense in duplicating efforts. Unless of course you are not prepared to make a PR, at which I will work on adding it.
Ah, sorry I dropped this guys. Unfortunately I never finished the testing. If you still want it I can make it available, but I assuming you have implemented by now.
It would be nice to have array rule improved, so it would take an optional parameter containing rue or set of rules to validate each element in the array accordingly. Probably the idea of composed rules mentioned in #100 or wrapping nested ruleset in parenthesis might be of use here to not mess with nested ruleset ie.
required|array:(string|min:3)
.