8000 Merge pull request #679 from Frondor/return-validator-data · laravel/lumen-framework@84f04c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit 84f04c1

Browse files
authored
Merge pull request #679 from Frondor/return-validator-data
Implementation of Laravel 5.5 feature: Request Data From Validation
2 parents 5c151e9 + 0dd064c commit 84f04c1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/Routing/ProvidesConvenienceMethods.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public static function formatErrorsUsing(BaseClosure $callback)
5454
* @param array $rules
5555
* @param array $messages
5656
* @param array $customAttributes
57-
* @return void
57+
* @return array
5858
*/
5959
public function validate(Request $request, array $rules, array $messages = [], array $customAttributes = [])
6060
{
@@ -63,6 +63,8 @@ public function validate(Request $request, array $rules, array $messages = [], a
6363
if ($validator->fails()) {
6464
$this->throwValidationException($request, $validator);
6565
}
66+
67+
return $validator->getData();
6668
}
6769

6870
/**

tests/FullApplicationTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,12 +468,19 @@ public function testValidationHelpers()
468468
$app = new Application;
469469

470470
$app->router->get('/', function (Illuminate\Http\Request $request) {
471-
$this->validate($request, ['name' => 'required']);
471+
$data = $this->validate($request, ['name' => 'required']);
472+
473+
return $data;
472474
});
473475

474476
$response = $app->handle(Request::create('/', 'GET'));
475477

476478
$this->assertEquals(422, $response->getStatusCode());
479+
480+
$response = $app->handle(Request::create('/', 'GET', ['name' => 'Jon']));
481+
482+
$this->assertEquals(200, $response->getStatusCode());
483+
$this->assertEquals($response->getContent(), '{"name":"Jon"}');
477484
}
478485

479486
public function testRedirectResponse()

0 commit comments

Comments
 (0)
0