Skip to content

Commit

Permalink
allow only keys directly on safe
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Aug 19, 2021
1 parent 3ccba24 commit 5e4ded8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
9 changes: 6 additions & 3 deletions src/Illuminate/Foundation/Http/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,11 +188,14 @@ protected function failedAuthorization()
/**
* Get a validated input container for the validated input.
*
* @return \Illuminate\Support\ValidatedInput
* @param array|null $keys
* @return \Illuminate\Support\ValidatedInput|array
*/
public function safe()
public function safe(array $keys = null)
{
return $this->validator->safe();
return is_array($keys)
? $this->validator->safe()->only($keys)
: $this->validator->safe();
}

/**
Expand Down
9 changes: 6 additions & 3 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,11 +510,14 @@ public function validateWithBag(string $errorBag)
/**
* Get a validated input container for the validated input.
*
* @return \Illuminate\Support\ValidatedInput
* @param array|null $keys
* @return \Illuminate\Support\ValidatedInput|array
*/
public function safe()
public function safe(array $keys = null)
{
return new ValidatedInput($this->validated());
return is_array($keys)
? (new ValidatedInput($this->validated()))->only($keys)
: new ValidatedInput($this->validated());
}

/**
Expand Down

0 comments on commit 5e4ded8

Please sign in to comment.