Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Return request data from controller validate() call #19033

Merged
merged 1 commit into from
May 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions src/Illuminate/Foundation/Validation/ValidatesRequests.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ trait ValidatesRequests
*
* @param \Illuminate\Contracts\Validation\Validator|array $validator
* @param \Illuminate\Http\Request|null $request
* @return void
* @return array
*/
public function validateWith($validator, Request $request = null)
{
$request = $request ?: app('request');
$request = $request ?: request();
Copy link
Contributor

@laurencei laurencei May 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this line need to change? I'm trying to understand the difference before/after?

edit: looks like your just switching to the helper, which has the same functionality under the hood? Is that right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@laurencei correct.


if (is_array($validator)) {
$validator = $this->getValidationFactory()->make($request->all(), $validator);
Expand All @@ -36,6 +36,8 @@ public function validateWith($validator, Request $request = null)
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}

return $request->only(array_keys($validator->getRules()));
}

/**
Expand All @@ -45,7 +47,7 @@ public function validateWith($validator, Request $request = null)
* @param array $rules
* @param array $messages
* @param array $customAttributes
* @return void
* @return array
*/
public function validate(Request $request, array $rules, array $messages = [], array $customAttributes = [])
{
Expand All @@ -54,6 +56,8 @@ public function validate(Request $request, array $rules, array $messages = [], a
if ($validator->fails()) {
$this->throwValidationException($request, $validator);
}

return $request->only(array_keys($rules));
}

/**
Expand All @@ -64,7 +68,7 @@ public function validate(Request $request, array $rules, array $messages = [], a
* @param array $rules
* @param array $messages
* @param array $customAttributes
* @return void
* @return array
*
* @throws \Illuminate\Validation\ValidationException
*/
Expand All @@ -73,6 +77,8 @@ public function validateWithBag($errorBag, Request $request, array $rules, array
$this->withErrorBag($errorBag, function () use ($request, $rules, $messages, $customAttributes) {
$this->validate($request, $rules, $messages, $customAttributes);
});

return $request->only(array_keys($rules));
}

/**
Expand Down