From ff0d04d103a2c2222135157b332a59e9e9dc65b2 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Tue, 25 Oct 2016 19:05:38 +0200 Subject: [PATCH 1/3] Keep files in the array after hydration --- src/Illuminate/Validation/Validator.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index db37ba8372bb..4ad10ab3e5f9 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -256,10 +256,8 @@ protected function hydrateFiles(array $data, $arrayKey = null) if ($value instanceof File) { $this->files[$newKey] = $value; - unset($data[$key]); } elseif (is_array($value) && ! empty($value) && empty($this->hydrateFiles($value, $newKey))) { - unset($data[$key]); } } From dcab0c43d696c92a44ed7e524802ca1f4e91ccff Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Tue, 25 Oct 2016 19:15:32 +0200 Subject: [PATCH 2/3] fix tests --- tests/Validation/ValidationValidatorTest.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index 9de505c418b9..b8c21cf5f897 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -564,7 +564,9 @@ public function testValidateRequired() $foo = new File(__FILE__, false); $v = new Validator($trans, ['name' => [$file, $foo]], ['name.0' => 'Required', 'name.1' => 'Required']); $this->assertTrue($v->passes()); - $this->assertEmpty($v->getData()); + + $v = new Validator($trans, ['files' => [$file, $foo]], ['files' => 'Required']); + $this->assertTrue($v->passes()); } public function testValidateRequiredWith() @@ -3227,7 +3229,7 @@ public function testFilesHydration() $file = new File(__FILE__, false); $v = new Validator($trans, ['file' => $file, 'text' => 'text'], ['text' => 'Required']); $this->assertEquals(['file' => $file], $v->getFiles()); - $this->assertEquals(['text' => 'text'], $v->getData()); + $this->assertEquals(['text' => 'text', 'file' => $file], $v->getData()); } public function testArrayOfFilesHydration() @@ -3237,7 +3239,7 @@ public function testArrayOfFilesHydration() $file2 = new File(__FILE__, false); $v = new Validator($trans, ['file' => [$file, $file2], 'text' => 'text'], ['text' => 'Required']); $this->assertEquals(['file.0' => $file, 'file.1' => $file2], $v->getFiles()); - $this->assertEquals(['text' => 'text'], $v->getData()); + $this->assertEquals(['text' => 'text', 'file' => [$file, $file2]], $v->getData()); } public function testMultipleFileUploads() From 539cde4eea9ced8c31740549ce6a3a353a4b232f Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Tue, 25 Oct 2016 19:20:55 +0200 Subject: [PATCH 3/3] fix style --- src/Illuminate/Validation/Validator.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Validation/Validator.php b/src/Illuminate/Validation/Validator.php index 4ad10ab3e5f9..b7bc47a1bca5 100755 --- a/src/Illuminate/Validation/Validator.php +++ b/src/Illuminate/Validation/Validator.php @@ -255,7 +255,6 @@ protected function hydrateFiles(array $data, $arrayKey = null) // we use to conveniently separate out these files from other data. if ($value instanceof File) { $this->files[$newKey] = $value; - } elseif (is_array($value) && ! empty($value) && empty($this->hydrateFiles($value, $newKey))) { }