File tree Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Expand file tree Collapse file tree 3 files changed +57
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Rakit \Validation \Rules ;
4
+
5
+ use Rakit \Validation \Rule ;
6
+
7
+ class RequiredWithoutAll extends Required
8
+ {
9
+ protected $ implicit = true ;
10
+
11
+ protected $ message = "The :attribute is required " ;
12
+
13
+ public function fillParameters (array $ params )
14
+ {
15
+ $ this ->params ['fields ' ] = $ params ;
16
+ return $ this ;
17
+ }
18
+
19
+ public function check ($ value )
20
+ {
21
+ $ this ->requireParameters (['fields ' ]);
22
+ $ fields = $ this ->parameter ('fields ' );
23
+ $ validator = $ this ->validation ->getValidator ();
24
+ $ required_validator = $ validator ('required ' );
25
+
26
+ foreach ($ fields as $ field ) {
27
+ if ($ this ->validation ->hasValue ($ field )) {
28
+ return true ;
29
+ }
30
+ }
31
+
32
+ $ this ->setAttributeAsRequired ();
33
+ return $ required_validator ->check ($ value , []);
34
+ }
35
+
36
+ }
Original file line number Diff line number Diff line change @@ -79,6 +79,7 @@ protected function registerBaseValidators()
79
79
'required_with ' => new Rules \RequiredWith ,
80
80
'required_without ' => new Rules \RequiredWithout ,
81
81
'required_with_all ' => new Rules \RequiredWithAll ,
82
+ 'required_without_all ' => new Rules \RequiredWithoutAll ,
82
83
'email ' => new Rules \Email ,
83
84
'alpha ' => new Rules \Alpha ,
84
85
'numeric ' => new Rules \Numeric ,
Original file line number Diff line number Diff line change @@ -241,6 +241,26 @@ public function testRequiredWithAllRule()
241
241
$ this ->assertFalse ($ v2 ->passes ());
242
242
}
243
243
244
+ public function testRequiredWithoutAllRule ()
245
+ {
246
+ $ v1 = $ this ->validator ->validate ([
247
+ 'b ' => '' ,
248
+ 'a ' => '1 '
249
+ ], [
250
+ 'b ' => 'required_without_all:a,c '
251
+ ]);
252
+
253
+ $ this ->assertTrue ($ v1 ->passes ());
254
+
255
+ $ v2 = $ this ->validator ->validate ([
256
+ 'b ' => '' ,
257
+ ], [
258
+ 'b ' => 'required_without_all:a,c '
259
+ ]);
260
+
261
+ $ this ->assertFalse ($ v2 ->passes ());
262
+ }
263
+
244
264
public function testRulePresent ()
245
265
{
246
266
$ v1 = $ this ->validator ->validate ([
You can’t perform that action at this time.
0 commit comments