@@ -106,6 +106,22 @@ public function hasAny($keys)
106
106
return Arr::hasAny ($ input , $ keys );
107
107
}
108
108
109
+ /**
110
+ * Apply the callback if the request contains the given input item key.
111
+ *
112
+ * @param string $key
113
+ * @param callable $callback
114
+ * @return $this|mixed
115
+ */
116
+ public function whenHas ($ key , callable $ callback )
117
+ {
118
+ if ($ this ->has ($ key )) {
119
+ return $ callback (data_get ($ this ->all (), $ key )) ?: $ this ;
120
+ }
121
+
122
+ return $ this ;
123
+ }
124
+
109
125
/**
110
126
* Determine if the request contains a non-empty value for an input item.
111
127
*
@@ -163,6 +179,22 @@ public function anyFilled($keys)
163
179
return false ;
164
180
}
165
181
182
+ /**
183
+ * Apply the callback if the request contains a non-empty value for the given input item key.
184
+ *
185
+ * @param string $key
186
+ * @param callable $callback
187
+ * @return $this|mixed
188
+ */
189
+ public function whenFilled ($ key , callable $ callback )
190
+ {
191
+ if ($ this ->filled ($ key )) {
192
+ return $ callback (data_get ($ this ->all (), $ key )) ?: $ this ;
193
+ }
194
+
195
+ return $ this ;
196
+ }
197
+
166
198
/**
167
199
* Determine if the request is missing a given input item key.
168
200
*
@@ -430,36 +462,4 @@ protected function retrieveItem($source, $key, $default)
430
462
431
463
return $ this ->$ source ->get ($ key , $ default );
432
464
}
433
-
434
- /**
435
- * Apply the callback if the request contains the given input item key.
436
- *
437
- * @param string $key
438
- * @param callable $callback
439
- * @return $this
440
- */
441
- public function whenHas ($ key , callable $ callback )
442
- {
443
- if ($ this ->has ($ key )) {
444
- $ callback (data_get ($ this ->all (), $ key ));
445
- }
446
-
447
- return $ this ;
448
- }
449
-
450
- /**
451
- * Apply the callback if the request contains a non-empty value for the given input item key.
452
- *
453
- * @param string $key
454
- * @param callable $callback
455
- * @return $this
456
- */
457
- public function whenFilled ($ key , callable $ callback )
458
- {
459
- if ($ this ->filled ($ key )) {
460
- $ callback (data_get ($ this ->all (), $ key ));
461
- }
462
-
463
- return $ this ;
464
- }
465
465
}
0 commit comments