Laravel 4 Validation - Nested Indexed Arrays?

后端 未结 3 1946
孤城傲影
孤城傲影 2021-01-02 08:38

I have an array of various things...

$foo = [];
$foo[\'stuff\'][\'item\'][0][\'title\' => \'flying_lotus\'];
$foo[\'stuff\'][\'item\'][1][\'title\' =>          


        
3条回答
  •  鱼传尺愫
    2021-01-02 09:15

    As @Cryode said, Laravel doesn't currently offer this functionality out of the box. I created a class extending the default Laravel Validator to add an iterate($attribute, $rules, $messages) method.

    It can also iterate recursively through arrays so that (for example) if you have any number of "books", each of which may have any number of "citations", this will still work, which @Cryode's example does not do, so this is a little more robust.

    https://github.com/penoonan/laravel-iterable-validator

提交回复
热议问题