Skip to content
Merged
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
6 changes: 5 additions & 1 deletion src/Illuminate/Validation/Rules/RequiredIf.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@ class RequiredIf implements Stringable
/**
* Create a new required validation rule based on a condition.
*
* @param (\Closure(): bool)|bool $condition
* @param (\Closure(): bool)|bool|null $condition
*/
public function __construct($condition)
{
if (is_null($condition)) {

Choose a reason for hiding this comment

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

I would love to learn why is_null = false, and instead of is_empty = false.

$condition = false;
}

if ($condition instanceof Closure || is_bool($condition)) {
$this->condition = $condition;
} else {
Expand Down
5 changes: 5 additions & 0 deletions tests/Validation/ValidationRequiredIfTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,10 @@ public function testRequiredIfRuleValidation()

$v = new Validator($trans, ['x' => 'foo'], ['x' => ['string', $rule]]);
$this->assertTrue($v->passes());

$rule = new RequiredIf(null);

$v = new Validator($trans, ['x' => 'foo'], ['x' => ['string', $rule]]);
$this->assertTrue($v->passes());
}
}