diff --git a/src/Illuminate/Foundation/Validation/ValidatesRequests.php b/src/Illuminate/Foundation/Validation/ValidatesRequests.php index 2f1a63227f1e..830da1036290 100644 --- a/src/Illuminate/Foundation/Validation/ValidatesRequests.php +++ b/src/Illuminate/Foundation/Validation/ValidatesRequests.php @@ -25,9 +25,7 @@ public function validateWith($validator, Request $request = null) $validator->validate(); - return $request->only(collect($validator->getRules())->keys()->map(function ($rule) { - return str_contains($rule, '.') ? explode('.', $rule)[0] : $rule; - })->unique()->toArray()); + return $this->extractInputFromRules($request, $validator->getRules()); } /** @@ -46,6 +44,18 @@ public function validate(Request $request, array $rules, ->make($request->all(), $rules, $messages, $customAttributes) ->validate(); + return $this->extractInputFromRules($request, $rules); + } + + /** + * Get request inputs using validator rules. + * + * @param \Illuminate\Http\Request $request + * @param array $rules + * @return array + */ + protected function extractInputFromRules(Request $request, $rules) + { return $request->only(collect($rules)->keys()->map(function ($rule) { return str_contains($rule, '.') ? explode('.', $rule)[0] : $rule; })->unique()->toArray());