Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Keep files in the $data array after hydration #16104

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,11 +255,8 @@ 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;

unset($data[$key]);
} elseif (is_array($value) && ! empty($value) &&
empty($this->hydrateFiles($value, $newKey))) {
unset($data[$key]);
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The elseif block is empty now. Should be removed, yeah?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, it's still calling $this->hydrateFiles($value, $newKey) inside the conditional. So I'm not sure how that should be handled.

Expand Down
8 changes: 5 additions & 3 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down