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
17 changes: 17 additions & 0 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,19 @@ protected function replacePlaceholderInString(string $value)
);
}

/**
* Replace each field parameter dot placeholder with dot.
*
* @param string $value
* @return string
*/
protected function replaceDotPlaceholderInParameters(array $parameters)
{
return array_map(function ($field) {
return str_replace($this->dotPlaceholder, '.', $field);
}, $parameters);
}

/**
* Add an after validation callback.
*
Expand Down Expand Up @@ -934,6 +947,10 @@ public function addFailure($attribute, $rule, $parameters = [])
return $this->excludeAttribute($attribute);
}

if ($this->dependsOnOtherFields($rule)) {
$parameters = $this->replaceDotPlaceholderInParameters($parameters);
}

$this->messages->add($attribute, $this->makeReplacements(
$this->getMessage($attributeWithPlaceholders, $rule), $attribute, $rule, $parameters
));
Expand Down
20 changes: 20 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7074,6 +7074,26 @@ public function testPlaceholdersAreReplaced()
$this->assertArrayHasKey('foo.bar', $v->validated());
}

public function testDotPlaceholdersInParametersAreReplacedIn()
{
$trans = $this->getIlluminateArrayTranslator();
$trans->addLines(['validation.required_without' => 'The :attribute field is required when :values is not present.'], 'en');

// Single parameter
$v = new Validator($trans, [], [
'name' => 'required_without:user\.name',
]);
$this->assertTrue($v->fails());
$this->assertSame('The name field is required when user.name is not present.', $v->messages()->first());

// Multiple parameters
$v = new Validator($trans, [], [
'name' => 'required_without:user\.name,admin\.name',
]);
$this->assertTrue($v->fails());
$this->assertSame('The name field is required when user.name / admin.name is not present.', $v->messages()->first());
}

public function testCoveringEmptyKeys()
{
$trans = $this->getIlluminateArrayTranslator();
Expand Down