0

For my Laravel 5.5 application, I'm trying to test an array inside of a request can have its indexes can be validated. How could this be achieved. The main rule I want to validate is that its numeric and can't be a zero value and the indexes must be in sequential order. The reason for this validation rule is because the indexes are going to inserted into my database.

...
...
items [
    [1] => [
        ...
    ]
    [2] => [
        ...
    ]
] 
user3732216
  • 1,579
  • 8
  • 29
  • 54
  • 1
    Looks like you need a simple array keys [filtering](https://stackoverflow.com/questions/4260086/php-how-to-use-array-filter-to-filter-array-keys). Take a look at the example in the accepted answer and adjust the code to meet your needs. – lesssugar Sep 24 '17 at 12:08
  • Does that do anything for my indexes which is what I asked about – user3732216 Sep 24 '17 at 12:12
  • Well, your "indexes" are keys, so yes, it does. You can use the Request array in the `array_filter()` function to get only the items which pass your validation rules - numeric and non-zero. Just so you know, it's usually **not** how you validate input with Laravel. The framework has a specific logic for [validation](https://laravel.com/docs/5.4/validation) in place. – lesssugar Sep 24 '17 at 12:18

0 Answers0