From 574bc9b90fb3a3f4c55f46abbc3e6458e7465151 Mon Sep 17 00:00:00 2001 From: Mohammad Mortazavi Date: Mon, 28 Aug 2023 13:11:48 +0330 Subject: [PATCH 1/3] handling array type in FormatsMessages; --- src/Illuminate/Validation/Concerns/FormatsMessages.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index 0758819daaad..fc339ac96492 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -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) { From 40421413e6f828be01fa87c93bb752ba9128b3b6 Mon Sep 17 00:00:00 2001 From: Mohammad Mortazavi Date: Mon, 28 Aug 2023 13:13:20 +0330 Subject: [PATCH 2/3] Tests for added; --- tests/Validation/ValidationValidatorTest.php | 23 ++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index e7178b674c30..a8e8b8653c17 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -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(); From d2bd2c23fed3d2f785e381f58770ca968abc49f2 Mon Sep 17 00:00:00 2001 From: Mohammad Mortazavi Date: Mon, 28 Aug 2023 13:31:30 +0330 Subject: [PATCH 3/3] Apply fixes from StyleCI --- .../Validation/Concerns/FormatsMessages.php | 2 +- tests/Validation/ValidationValidatorTest.php | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index fc339ac96492..4d4042a4e10f 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -442,7 +442,7 @@ public function getDisplayableValue($attribute, $value) return $this->customValues[$attribute][$value]; } - if ( is_array( $value ) ) { + if (is_array($value)) { return 'array'; } diff --git a/tests/Validation/ValidationValidatorTest.php b/tests/Validation/ValidationValidatorTest.php index a8e8b8653c17..23bf82651098 100755 --- a/tests/Validation/ValidationValidatorTest.php +++ b/tests/Validation/ValidationValidatorTest.php @@ -1419,23 +1419,23 @@ public function testRequiredIf() public function testRequiredIfArrayToStringConversationErrorException() { $trans = $this->getIlluminateArrayTranslator(); - $v = new Validator( $trans, [ + $v = new Validator($trans, [ 'is_customer' => 1, 'fullname' => null, ], [ 'is_customer' => 'required|boolean', - 'fullname' => 'required_if:is_customer,true' - ] ); + 'fullname' => 'required_if:is_customer,true', + ]); $this->assertTrue($v->fails()); $trans = $this->getIlluminateArrayTranslator(); - $v = new Validator( $trans, [ + $v = new Validator($trans, [ 'is_customer' => ['test'], 'fullname' => null, ], [ 'is_customer' => 'required|boolean', - 'fullname' => 'required_if:is_customer,true' - ] ); + 'fullname' => 'required_if:is_customer,true', + ]); $this->assertTrue($v->fails()); }