File tree Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Expand file tree Collapse file tree 2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ public function check($value)
23
23
24
24
$ anotherAttribute = $ this ->parameter ('field ' );
25
25
$ definedValues = $ this ->parameter ('values ' );
26
- $ anotherValue = $ this ->validation ->getValue ($ anotherAttribute );
26
+ $ anotherValue = $ this ->getAttribute () ->getValue ($ anotherAttribute );
27
27
28
28
$ validator = $ this ->validation ->getValidator ();
29
29
$ required_validator = $ validator ('required ' );
Original file line number Diff line number Diff line change @@ -808,4 +808,38 @@ public function testCustomMessageInArrayValidation()
808
808
$ this ->assertEquals ($ errors ->first ('cart.*.attributes.*.value ' ), 'Item 2 attribute 1 value is required ' );
809
809
}
810
810
811
+ public function testRequiredIfOnArrayAttribute ()
812
+ {
813
+ $ validation = $ this ->validator ->validate ([
814
+ 'products ' => [
815
+ // invalid because has_notes is not empty
816
+ '10 ' => [
817
+ 'quantity ' => 8 ,
818
+ 'has_notes ' => 1 ,
819
+ 'notes ' => ''
820
+ ],
821
+ // valid because has_notes is null
822
+ '12 ' => [
823
+ 'quantity ' => 0 ,
824
+ 'has_notes ' => null ,
825
+ 'notes ' => ''
826
+ ],
827
+ // valid because no has_notes
828
+ '14 ' => [
829
+ 'quantity ' => 0 ,
830
+ 'notes ' => ''
831
+ ],
832
+ ]
833
+ ], [
834
+ 'products.*.notes ' => 'required_if:products.*.has_notes,1 ' ,
835
+ ]);
836
+
837
+ $ this ->assertFalse ($ validation ->passes ());
838
+
839
+ $ errors = $ validation ->errors ();
840
+ $ this ->assertNotNull ($ errors ->first ('products.10.notes ' ));
841
+ $ this ->assertNull ($ errors ->first ('products.12.notes ' ));
842
+ $ this ->assertNull ($ errors ->first ('products.14.notes ' ));
843
+ }
844
+
811
845
}
You can’t perform that action at this time.
0 commit comments