imJohnBon's avatar

Validating fields that are passed in a group?

So, I'm in a situation where users have photo galleries where they can add really any number of photos. So, my HTML looks something like this:


...input name="photo_gallery[]" type="file"...
...input name="photo_gallery[]" type="file"...
...input name="photo_gallery[]" type="file"...

So on and so forth, there could be 15 of those in theory, or none. My question is, how do I go about validating something like this? Obviously I need to make sure an actual image is uploaded, etc.

I should note that I'm also using Laravel 5.

0 likes
5 replies
pmall's avatar

I regularly have this problem too and there is no solution (in my knowlege) except constructing a rule array based on the number of fields in the input array. (you can write rules like 'photos.1.name', 'photos.2.name', etc...).

Please someone hack the validator to handle this usecase.

imJohnBon's avatar

@bestmomo Interesting, will need to parse through that thread later.

@bashy Indexing like that only works if you know how many items are going to be submitted, right? In my case where it could be 0, 2, 12, or any number, I couldn't specify each one.

bashy's avatar

Yeah I guess, only way around it is a foreach or each array

Please or to participate in this conversation.