From 8461cdd77c7c4b23e9f545dcad13a10e6359e430 Mon Sep 17 00:00:00 2001 From: Adam Date: Wed, 7 Mar 2018 13:18:56 -0700 Subject: [PATCH] [5.6] Fix use of unique() --- src/Illuminate/Validation/Validator.php | 2 +- tests/Validation/ValidationValidatorTest.php | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index f3bd80b64cb0..f2684d5628dd 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -310,7 +310,7 @@ public function validate() return $data->only(collect($this->getRules())->keys()->map(function ($rule) { return Str::contains($rule, '.') ? explode('.', $rule)[0] : $rule; - }))->unique()->toArray(); + })->unique())->toArray(); } /** diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 2e8a97ef887c..b0ee1f2e6454 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -3876,12 +3876,15 @@ public function message() public function testValidateReturnsValidatedData() { - $post = ['first' => 'john', 'last' => 'doe', 'type' => 'admin']; + $post = ['first' => 'john', 'preferred'=>'john', 'last' => 'doe', 'type' => 'admin']; - $v = new Validator($this->getIlluminateArrayTranslator(), $post, ['first' => 'required']); + $v = new Validator($this->getIlluminateArrayTranslator(), $post, ['first' => 'required', 'preferred'=> 'required']); + $v->sometimes('type', 'required', function () { + return false; + }); $data = $v->validate(); - $this->assertEquals(['first' => 'john'], $data); + $this->assertEquals(['first' => 'john', 'preferred' => 'john'], $data); } protected function getTranslator()