Skip to content

Commit

Permalink
[10.x] Array to string conversion error exception (#48219)
Browse files Browse the repository at this point in the history
* handling array type in FormatsMessages;

* Tests for added;

* Apply fixes from StyleCI
  • Loading branch information
hans-thomas authored Aug 28, 2023
1 parent 12b20c3 commit a76d8b2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Illuminate/Validation/Concerns/FormatsMessages.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,10 @@ public function getDisplayableValue($attribute, $value)
return $this->customValues[$attribute][$value];
}

if (is_array($value)) {
return 'array';
}

$key = "validation.values.{$attribute}.{$value}";

if (($line = $this->translator->get($key)) !== $key) {
Expand Down
23 changes: 23 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,29 @@ public function testRequiredIf()
$this->assertSame('The baz field is required when foo is empty.', $v->messages()->first('baz'));
}

public function testRequiredIfArrayToStringConversationErrorException()
{
$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, [
'is_customer' => 1,
'fullname' => null,
], [
'is_customer' => 'required|boolean',
'fullname' => 'required_if:is_customer,true',
]);
$this->assertTrue($v->fails());

$trans = $this->getIlluminateArrayTranslator();
$v = new Validator($trans, [
'is_customer' => ['test'],
'fullname' => null,
], [
'is_customer' => 'required|boolean',
'fullname' => 'required_if:is_customer,true',
]);
$this->assertTrue($v->fails());
}

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

0 comments on commit a76d8b2

Please sign in to comment.