File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ public function __construct(array $input)
30
30
/**
31
31
* Get a subset containing the provided keys with values from the input data.
32
32
*
33
- * @param array| mixed $keys
33
+ * @param mixed $keys
34
34
* @return array
35
35
*/
36
36
public function only ($ keys )
@@ -55,7 +55,7 @@ public function only($keys)
55
55
/**
56
56
* Get all of the input except for a specified array of items.
57
57
*
58
- * @param array| mixed $keys
58
+ * @param mixed $keys
59
59
* @return array
60
60
*/
61
61
public function except ($ keys )
@@ -100,6 +100,36 @@ public function all()
100
100
return $ this ->input ;
101
101
}
102
102
103
+ /**
104
+ * Determine if the validated input has one or more keys.
105
+ *
106
+ * @param mixed $keys
107
+ * @return bool
108
+ */
109
+ public function has ($ keys )
110
+ {
111
+ $ keys = is_array ($ keys ) ? $ keys : func_get_args ();
112
+
113
+ foreach ($ keys as $ key ) {
114
+ if (! Arr::has ($ this ->input , $ key )) {
115
+ return false ;
116
+ }
117
+ }
118
+
119
+ return true ;
120
+ }
121
+
122
+ /**
123
+ * Determine if the validated input is missing one or more keys.
124
+ *
125
+ * @param mixed $keys
126
+ * @return bool
127
+ */
128
+ public function missing ($ keys )
129
+ {
130
+ return ! $ this ->has ($ keys );
131
+ }
132
+
103
133
/**
104
134
* Get the instance as an array.
105
135
*
Original file line number Diff line number Diff line change @@ -30,4 +30,18 @@ public function test_can_merge_items()
30
30
$ this ->assertEquals (['name ' => 'Taylor ' ], $ input ->except (['votes ' ]));
31
31
$ this ->assertEquals (['name ' => 'Taylor ' , 'votes ' => 100 ], $ input ->all ());
32
32
}
33
+
34
+ public function test_input_existence ()
35
+ {
36
+ $ inputA = new ValidatedInput (['name ' => 'Taylor ' ]);
37
+
38
+ $ this ->assertEquals (true , $ inputA ->has ('name ' ));
39
+ $ this ->assertEquals (true , $ inputA ->missing ('votes ' ));
40
+ $ this ->assertEquals (true , $ inputA ->missing (['votes ' ]));
41
+ $ this ->assertEquals (false , $ inputA ->missing ('name ' ));
42
+
43
+ $ inputB = new ValidatedInput (['name ' => 'Taylor ' , 'votes ' => 100 ]);
44
+
45
+ $ this ->assertEquals (true , $ inputB ->has (['name ' , 'votes ' ]));
46
+ }
33
47
}
You can’t perform that action at this time.
0 commit comments