Skip to content

Commit a76d8b2

Browse files
authored
[10.x] Array to string conversion error exception (#48219)
* handling array type in FormatsMessages; * Tests for added; * Apply fixes from StyleCI
1 parent 12b20c3 commit a76d8b2

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/Illuminate/Validation/Concerns/FormatsMessages.php

+4
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,10 @@ public function getDisplayableValue($attribute, $value)
442442
return $this->customValues[$attribute][$value];
443443
}
444444

445+
if (is_array($value)) {
446+
return 'array';
447+
}
448+
445449
$key = "validation.values.{$attribute}.{$value}";
446450

447451
if (($line = $this->translator->get($key)) !== $key) {

tests/Validation/ValidationValidatorTest.php

+23
Original file line numberDiff line numberDiff line change
@@ -1416,6 +1416,29 @@ public function testRequiredIf()
14161416
$this->assertSame('The baz field is required when foo is empty.', $v->messages()->first('baz'));
14171417
}
14181418

1419+
public function testRequiredIfArrayToStringConversationErrorException()
1420+
{
1421+
$trans = $this->getIlluminateArrayTranslator();
1422+
$v = new Validator($trans, [
1423+
'is_customer' => 1,
1424+
'fullname' => null,
1425+
], [
1426+
'is_customer' => 'required|boolean',
1427+
'fullname' => 'required_if:is_customer,true',
1428+
]);
1429+
$this->assertTrue($v->fails());
1430+
1431+
$trans = $this->getIlluminateArrayTranslator();
1432+
$v = new Validator($trans, [
1433+
'is_customer' => ['test'],
1434+
'fullname' => null,
1435+
], [
1436+
'is_customer' => 'required|boolean',
1437+
'fullname' => 'required_if:is_customer,true',
1438+
]);
1439+
$this->assertTrue($v->fails());
1440+
}
1441+
14191442
public function testRequiredUnless()
14201443
{
14211444
$trans = $this->getIlluminateArrayTranslator();

0 commit comments

Comments
 (0)