Skip to content

Commit

Permalink
[5.6] Fix use of unique() (#23432)
Browse files Browse the repository at this point in the history
  • Loading branch information
adam1010 authored and taylorotwell committed Mar 7, 2018
1 parent 46d6afb commit 7bd8c6e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

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

0 comments on commit 7bd8c6e

Please sign in to comment.