File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -319,6 +319,37 @@ public function testConditionalRulesCanBeAddedToForEachWithObject()
319
319
], $ v ->getMessageBag ()->toArray ());
320
320
}
321
321
322
+ public function testForEachWithEmptyAndNullValues ()
323
+ {
324
+ $ data = [
325
+ 'items ' => [
326
+ ['discounts ' => null ],
327
+ ['discounts ' => []],
328
+ ['discounts ' => [null ]],
329
+ ],
330
+ ];
331
+
332
+ $ rules = [
333
+ 'items.* ' => Rule::forEach (function () {
334
+ return [
335
+ 'discounts ' => 'required|array ' ,
336
+ 'discounts.* ' => 'required|array ' ,
337
+ ];
338
+ }),
339
+ ];
340
+
341
+ $ v = new Validator ($ this ->getIlluminateArrayTranslator (), $ data , $ rules );
342
+ $ this ->assertFalse ($ v ->passes ());
343
+ $ this ->assertEquals (
344
+ [
345
+ 'items.0.discounts ' => ['validation.required ' ],
346
+ 'items.1.discounts ' => ['validation.required ' ],
347
+ 'items.2.discounts.0 ' => ['validation.required ' ],
348
+ ],
349
+ $ v ->getMessageBag ()->toArray ()
350
+ );
351
+ }
352
+
322
353
public function getIlluminateArrayTranslator ()
323
354
{
324
355
return new Translator (
You can’t perform that action at this time.
0 commit comments