Skip to content

Commit

Permalink
Fix validating present and nullable (#18173)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Mar 1, 2017
1 parent e09b9eb commit 3e8e085
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,7 @@ protected function isNotNullIfMarkedAsNullable($attribute, $value)
return true;
}

return ! is_null($value);
return ! is_null(Arr::get($this->data, $attribute, 0));
}

/**
Expand Down
6 changes: 6 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,12 @@ public function testValidatePresent()
$v = new Validator($trans, [], ['name' => 'present']);
$this->assertFalse($v->passes());

$v = new Validator($trans, [], ['name' => 'present|nullable']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['name' => null], ['name' => 'present|nullable']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['name' => ''], ['name' => 'present']);
$this->assertTrue($v->passes());

Expand Down

0 comments on commit 3e8e085

Please sign in to comment.