Skip to content

Commit

Permalink
Add a "validated" method to the form request
Browse files Browse the repository at this point in the history
  • Loading branch information
JosephSilber committed May 9, 2017
1 parent d77b13a commit eb02670
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Http/FormRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,16 @@ protected function createDefaultValidator(ValidationFactory $factory)
);
}

/**
* Get the validated data from the request.
*
* @return array
*/
public function validated()
{
return $this->only(array_keys($this->container->call([$this, 'rules'])));
}

/**
* Get data to be validated from the request.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Foundation/FoundationFormRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ public function tearDown()
$this->mocks = [];
}

public function test_validated_method_returns_the_validated_data()
{
$request = $this->createRequest(['name' => 'specified', 'with' => 'extras']);

$request->validate();

$this->assertEquals(['name' => 'specified'], $request->validated());
}

/**
* @expectedException \Illuminate\Validation\ValidationException
*/
Expand Down

0 comments on commit eb02670

Please sign in to comment.