diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index fdcec8850059..f3bd80b64cb0 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -306,7 +306,11 @@ public function validate() throw new ValidationException($this); } - return $this->getDataForRules(); + $data = collect($this->getData()); + + return $data->only(collect($this->getRules())->keys()->map(function ($rule) { + return Str::contains($rule, '.') ? explode('.', $rule)[0] : $rule; + }))->unique()->toArray(); } /** @@ -727,20 +731,6 @@ public function getData() return $this->data; } - /** - * Get the data under validation only for the loaded rules. - * - * @return array - */ - public function getDataForRules() - { - $ruleKeys = collect($this->getRules())->keys()->map(function ($rule) { - return explode('.', $rule, 2)[0]; - })->unique()->toArray(); - - return collect($this->getData())->only($ruleKeys)->toArray(); - } - /** * Set the data under validation. * diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index b3121a0d6c77..2e8a97ef887c 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -3874,28 +3874,14 @@ public function message() $this->assertTrue($rule->called); } - public function testGetDataForRules() + public function testValidateReturnsValidatedData() { - $post = ['first'=>'john', 'last'=>'doe', 'type' => 'admin']; + $post = ['first' => 'john', 'last' => 'doe', 'type' => 'admin']; $v = new Validator($this->getIlluminateArrayTranslator(), $post, ['first' => 'required']); - $data = $v->getDataForRules(); + $data = $v->validate(); - $this->assertSame($data, ['first'=>'john']); - - $v->sometimes('last', 'required', function () { - return true; - }); - $data = $v->getDataForRules(); - - $this->assertSame($data, ['first'=>'john', 'last'=>'doe']); - - $v->sometimes('type', 'required', function () { - return false; - }); - $data = $v->getDataForRules(); - - $this->assertSame($data, ['first'=>'john', 'last'=>'doe']); + $this->assertEquals(['first' => 'john'], $data); } protected function getTranslator()