From 55cee39d0b983ad3bdf3179ac479334cc4946c3d Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 11 Oct 2025 23:56:57 +0100 Subject: [PATCH 01/17] init fix --- src/Illuminate/Validation/Concerns/FormatsMessages.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index 6b1ba8f24195..1c7c9de2f2b0 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -101,7 +101,9 @@ protected function getFromLocalArray($attribute, $lowerRule, $source = null) { $source = $source ?: $this->customMessages; - $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute]; + $shortRule = strtolower(class_basename($lowerRule)); + + $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute, "{$attribute}.$shortRule"]; // First we will check for a custom message for an attribute specific rule // message for the fields, then we will check for a general custom line From ad01df40ae37ed7861beae716bed70f90a3e6c17 Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 11 Oct 2025 23:57:01 +0100 Subject: [PATCH 02/17] Update ValidationEnumRuleTest.php --- tests/Validation/ValidationEnumRuleTest.php | 23 +++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/tests/Validation/ValidationEnumRuleTest.php b/tests/Validation/ValidationEnumRuleTest.php index bf9ec319dc66..6490f84e3181 100644 --- a/tests/Validation/ValidationEnumRuleTest.php +++ b/tests/Validation/ValidationEnumRuleTest.php @@ -277,6 +277,29 @@ public static function conditionalCasesDataProvider(): array ]; } + public function testCustomMessageUsingDotNotationWorks() + { + $v = new Validator( + resolve('translator'), + [ + 'status' => 'invalid_value', + ], + [ + 'status' => new Enum(StringStatus::class), + ], + [ + 'status.enum' => 'Please choose a valid pattern (dot notation)', + ] + ); + + $this->assertTrue($v->fails()); + + $this->assertEquals( + ['Please choose a valid pattern (dot notation)'], + $v->messages()->get('status') + ); + } + protected function setUp(): void { $container = Container::getInstance(); From f6ddf38a019eb37ddef1b539cff1ffdfbe44da7c Mon Sep 17 00:00:00 2001 From: Jack Date: Sat, 11 Oct 2025 23:57:26 +0100 Subject: [PATCH 03/17] Update tests.yml --- .github/workflows/tests.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fa5159f4c643..e258fb49a2a4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,12 +2,6 @@ name: tests on: push: - branches: - - master - - '*.x' - pull_request: - schedule: - - cron: '0 0 * * *' jobs: linux_tests: From 25ed003d5be6437a0432c5f7b07cc991f5e5664b Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:12:46 +0100 Subject: [PATCH 04/17] rename --- src/Illuminate/Validation/Concerns/FormatsMessages.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index 1c7c9de2f2b0..f3897a1a7a7d 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -101,9 +101,9 @@ protected function getFromLocalArray($attribute, $lowerRule, $source = null) { $source = $source ?: $this->customMessages; - $shortRule = strtolower(class_basename($lowerRule)); + $shortHandRule = strtolower(class_basename($lowerRule)); - $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute, "{$attribute}.$shortRule"]; + $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute, "{$attribute}.$shortHandRule"]; // First we will check for a custom message for an attribute specific rule // message for the fields, then we will check for a general custom line From 1aeccd94869c8b3224b9c83d44544b4601684ef4 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:12:56 +0100 Subject: [PATCH 05/17] improve test --- tests/Validation/ValidationEnumRuleTest.php | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tests/Validation/ValidationEnumRuleTest.php b/tests/Validation/ValidationEnumRuleTest.php index 6490f84e3181..f8fe4059c444 100644 --- a/tests/Validation/ValidationEnumRuleTest.php +++ b/tests/Validation/ValidationEnumRuleTest.php @@ -277,27 +277,29 @@ public static function conditionalCasesDataProvider(): array ]; } - public function testCustomMessageUsingDotNotationWorks() + public function testCustomMessageUsingDotNotationOrFqcnWorks() { $v = new Validator( resolve('translator'), [ 'status' => 'invalid_value', + 'status_fqcn' => 'another_invalid', ], [ 'status' => new Enum(StringStatus::class), + 'status_fqcn' => new Enum(StringStatus::class), ], [ 'status.enum' => 'Please choose a valid pattern (dot notation)', + 'status_fqcn.Illuminate\Validation\Rules\Enum' => 'Please choose a valid pattern (fqcn)', ] ); - $this->assertTrue($v->fails()); - $this->assertEquals( - ['Please choose a valid pattern (dot notation)'], - $v->messages()->get('status') - ); + $this->assertSame([ + 'Please choose a valid pattern (fqcn)', + 'Please choose a valid pattern (dot notation)', + ], $v->messages()->all()); } protected function setUp(): void From 529d70d8f80aaa3d104635dfba450457e3b8e179 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:14:24 +0100 Subject: [PATCH 06/17] revert local test changes --- .github/workflows/tests.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e258fb49a2a4..fa5159f4c643 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,12 @@ name: tests on: push: + branches: + - master + - '*.x' + pull_request: + schedule: + - cron: '0 0 * * *' jobs: linux_tests: From c11598cd4c128430d62aa0a1da4d3a3a4fb305ce Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:36:35 +0100 Subject: [PATCH 07/17] Update ValidationEnumRuleTest.php --- tests/Validation/ValidationEnumRuleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Validation/ValidationEnumRuleTest.php b/tests/Validation/ValidationEnumRuleTest.php index f8fe4059c444..97705c5de75e 100644 --- a/tests/Validation/ValidationEnumRuleTest.php +++ b/tests/Validation/ValidationEnumRuleTest.php @@ -297,8 +297,8 @@ public function testCustomMessageUsingDotNotationOrFqcnWorks() $this->assertTrue($v->fails()); $this->assertSame([ - 'Please choose a valid pattern (fqcn)', 'Please choose a valid pattern (dot notation)', + 'Please choose a valid pattern (fqcn)', ], $v->messages()->all()); } From f7c7ce3586466e4de0e4bab65598078d0d21ceca Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:40:32 +0100 Subject: [PATCH 08/17] Update ValidationEnumRuleTest.php --- tests/Validation/ValidationEnumRuleTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Validation/ValidationEnumRuleTest.php b/tests/Validation/ValidationEnumRuleTest.php index 97705c5de75e..35a8811ae200 100644 --- a/tests/Validation/ValidationEnumRuleTest.php +++ b/tests/Validation/ValidationEnumRuleTest.php @@ -294,6 +294,7 @@ public function testCustomMessageUsingDotNotationOrFqcnWorks() 'status_fqcn.Illuminate\Validation\Rules\Enum' => 'Please choose a valid pattern (fqcn)', ] ); + $this->assertTrue($v->fails()); $this->assertSame([ From e2de196b34e66ad1574e44f5dc9ae59fdef6063a Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:42:31 +0100 Subject: [PATCH 09/17] run tests in local branch to check --- .github/workflows/databases.yml | 4 ---- .github/workflows/queues.yml | 4 ---- .github/workflows/tests.yml | 6 ------ 3 files changed, 14 deletions(-) diff --git a/.github/workflows/databases.yml b/.github/workflows/databases.yml index 6172854ee02f..ab0346d663d9 100644 --- a/.github/workflows/databases.yml +++ b/.github/workflows/databases.yml @@ -2,10 +2,6 @@ name: databases on: push: - branches: - - master - - '*.x' - pull_request: jobs: mysql_57: diff --git a/.github/workflows/queues.yml b/.github/workflows/queues.yml index 3df36c7d6c82..2c212d91cc0e 100644 --- a/.github/workflows/queues.yml +++ b/.github/workflows/queues.yml @@ -2,10 +2,6 @@ name: queues on: push: - branches: - - master - - '*.x' - pull_request: jobs: sync: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index fa5159f4c643..e258fb49a2a4 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,12 +2,6 @@ name: tests on: push: - branches: - - master - - '*.x' - pull_request: - schedule: - - cron: '0 0 * * *' jobs: linux_tests: From 0008e42bac6e240977430aa4d33fdcfd144ce070 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:54:13 +0100 Subject: [PATCH 10/17] improve shorthand rule --- src/Illuminate/Validation/Concerns/FormatsMessages.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index f3897a1a7a7d..ab2171b9d1f6 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -101,9 +101,13 @@ protected function getFromLocalArray($attribute, $lowerRule, $source = null) { $source = $source ?: $this->customMessages; + $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute]; + $shortHandRule = strtolower(class_basename($lowerRule)); - $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute, "{$attribute}.$shortHandRule"]; + if (! isset($keys[$shortHandRule])) { + $keys[] = "{$attribute}.{$shortHandRule}"; + } // First we will check for a custom message for an attribute specific rule // message for the fields, then we will check for a general custom line From a548d2ed8d9fda91e52082ed06e4580c9258f851 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:56:10 +0100 Subject: [PATCH 11/17] Str::snake rather than native strtolower --- src/Illuminate/Validation/Concerns/FormatsMessages.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index ab2171b9d1f6..7bbbd91cf2c3 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -103,7 +103,7 @@ protected function getFromLocalArray($attribute, $lowerRule, $source = null) $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute]; - $shortHandRule = strtolower(class_basename($lowerRule)); + $shortHandRule = Str::snake(class_basename($lowerRule)); if (! isset($keys[$shortHandRule])) { $keys[] = "{$attribute}.{$shortHandRule}"; From 7caba18f9e93463872d93595150be26a5e81998a Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:56:19 +0100 Subject: [PATCH 12/17] Revert "run tests in local branch to check" This reverts commit e2de196b34e66ad1574e44f5dc9ae59fdef6063a. --- .github/workflows/databases.yml | 4 ++++ .github/workflows/queues.yml | 4 ++++ .github/workflows/tests.yml | 6 ++++++ 3 files changed, 14 insertions(+) diff --git a/.github/workflows/databases.yml b/.github/workflows/databases.yml index ab0346d663d9..6172854ee02f 100644 --- a/.github/workflows/databases.yml +++ b/.github/workflows/databases.yml @@ -2,6 +2,10 @@ name: databases on: push: + branches: + - master + - '*.x' + pull_request: jobs: mysql_57: diff --git a/.github/workflows/queues.yml b/.github/workflows/queues.yml index 2c212d91cc0e..3df36c7d6c82 100644 --- a/.github/workflows/queues.yml +++ b/.github/workflows/queues.yml @@ -2,6 +2,10 @@ name: queues on: push: + branches: + - master + - '*.x' + pull_request: jobs: sync: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index e258fb49a2a4..fa5159f4c643 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -2,6 +2,12 @@ name: tests on: push: + branches: + - master + - '*.x' + pull_request: + schedule: + - cron: '0 0 * * *' jobs: linux_tests: From 97d12efbacc754645dd357064ef276d841be9e70 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 00:59:16 +0100 Subject: [PATCH 13/17] Update ValidationEnumRuleTest.php --- tests/Validation/ValidationEnumRuleTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Validation/ValidationEnumRuleTest.php b/tests/Validation/ValidationEnumRuleTest.php index 35a8811ae200..ff308090acd5 100644 --- a/tests/Validation/ValidationEnumRuleTest.php +++ b/tests/Validation/ValidationEnumRuleTest.php @@ -277,7 +277,7 @@ public static function conditionalCasesDataProvider(): array ]; } - public function testCustomMessageUsingDotNotationOrFqcnWorks() + public function testCustomMessageUsingDotNotationAndFqcnWorks() { $v = new Validator( resolve('translator'), From d660b091cb0e9febc74fc3bc2b10d6888caeff6d Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 01:09:29 +0100 Subject: [PATCH 14/17] final test bits --- tests/Validation/ValidationAnyOfRuleTest.php | 26 ++++++++++++++++++++ tests/Validation/ValidationEnumRuleTest.php | 8 +++--- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/tests/Validation/ValidationAnyOfRuleTest.php b/tests/Validation/ValidationAnyOfRuleTest.php index f0806182c693..ee9474a707a6 100644 --- a/tests/Validation/ValidationAnyOfRuleTest.php +++ b/tests/Validation/ValidationAnyOfRuleTest.php @@ -349,6 +349,32 @@ protected function setUpRuleSets() ]; } + public function testCustomMessageUsingDotNotationAndFqcnWorks() + { + $v = new Validator( + resolve('translator'), + [ + 'string' => 123, + 'string_fqcn' => 456, + ], + [ + 'string' => Rule::anyOf(['string']), + 'string_fqcn' => Rule::anyOf(['string']), + ], + [ + 'string.any_of' => 'Please choose a valid string (dot notation)', + 'string_fqcn.Illuminate\Validation\Rules\AnyOf' => 'Please choose a valid string (fqcn)', + ] + ); + + $this->assertTrue($v->fails()); + + $this->assertSame([ + 'Please choose a valid string (dot notation)', + 'Please choose a valid string (fqcn)', + ], $v->messages()->all()); + } + protected function setUp(): void { parent::setUp(); diff --git a/tests/Validation/ValidationEnumRuleTest.php b/tests/Validation/ValidationEnumRuleTest.php index ff308090acd5..a0399805def4 100644 --- a/tests/Validation/ValidationEnumRuleTest.php +++ b/tests/Validation/ValidationEnumRuleTest.php @@ -290,16 +290,16 @@ public function testCustomMessageUsingDotNotationAndFqcnWorks() 'status_fqcn' => new Enum(StringStatus::class), ], [ - 'status.enum' => 'Please choose a valid pattern (dot notation)', - 'status_fqcn.Illuminate\Validation\Rules\Enum' => 'Please choose a valid pattern (fqcn)', + 'status.enum' => 'Please choose a valid status (dot notation)', + 'status_fqcn.Illuminate\Validation\Rules\Enum' => 'Please choose a valid status (fqcn)', ] ); $this->assertTrue($v->fails()); $this->assertSame([ - 'Please choose a valid pattern (dot notation)', - 'Please choose a valid pattern (fqcn)', + 'Please choose a valid status (dot notation)', + 'Please choose a valid status (fqcn)', ], $v->messages()->all()); } From ce349e30da04402c3fcb605b52adf8156b6ab618 Mon Sep 17 00:00:00 2001 From: Jack Date: Sun, 12 Oct 2025 01:37:08 +0100 Subject: [PATCH 15/17] final adjustments --- src/Illuminate/Validation/Concerns/FormatsMessages.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index 7bbbd91cf2c3..ad045a42d981 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -103,10 +103,10 @@ protected function getFromLocalArray($attribute, $lowerRule, $source = null) $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute]; - $shortHandRule = Str::snake(class_basename($lowerRule)); + $shortHandRule = "{$attribute}.".Str::snake(class_basename($lowerRule)); - if (! isset($keys[$shortHandRule])) { - $keys[] = "{$attribute}.{$shortHandRule}"; + if (! in_array($shortHandRule, $keys)) { + $keys[] = $shortHandRule; } // First we will check for a custom message for an attribute specific rule From 89eaacc6501ebca5198210330fc0863547a3023d Mon Sep 17 00:00:00 2001 From: Jack Date: Mon, 13 Oct 2025 11:06:51 +0100 Subject: [PATCH 16/17] prove it fixes can too --- tests/Validation/ValidationRuleCanTest.php | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/tests/Validation/ValidationRuleCanTest.php b/tests/Validation/ValidationRuleCanTest.php index 8b7f7c92173d..71275bf65873 100644 --- a/tests/Validation/ValidationRuleCanTest.php +++ b/tests/Validation/ValidationRuleCanTest.php @@ -90,6 +90,32 @@ public function testValidationPasses() $this->assertTrue($v->passes()); } + public function testCustomMessageUsingDotNotationAndFqcnWorks() + { + $v = new Validator( + resolve('translator'), + [ + 'company' => '1', + 'company_fqcn' => '1', + ], + [ + 'company' => new Can('update-company', [\App\Models\Company::class, new stdClass]), + 'company_fqcn' => new Can('update-company', [\App\Models\Company::class, new stdClass]), + ], + [ + 'company.can' => 'You dont have permission (dot notation)', + 'company_fqcn.Illuminate\Validation\Rules\Can' => 'You dont have permission (fqcn)', + ] + ); + + $this->assertTrue($v->fails()); + + $this->assertSame([ + 'You dont have permission (dot notation)', + 'You dont have permission (fqcn)', + ], $v->messages()->all()); + } + /** * Get the Gate instance from the container. * From e34d6dae76d3ce0d0e6e0091d8878a7c4ebd04ea Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Tue, 14 Oct 2025 12:33:20 -0500 Subject: [PATCH 17/17] Update FormatsMessages.php --- src/Illuminate/Validation/Concerns/FormatsMessages.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Illuminate/Validation/Concerns/FormatsMessages.php b/src/Illuminate/Validation/Concerns/FormatsMessages.php index ad045a42d981..9fac13cb8298 100644 --- a/src/Illuminate/Validation/Concerns/FormatsMessages.php +++ b/src/Illuminate/Validation/Concerns/FormatsMessages.php @@ -103,10 +103,10 @@ protected function getFromLocalArray($attribute, $lowerRule, $source = null) $keys = ["{$attribute}.{$lowerRule}", $lowerRule, $attribute]; - $shortHandRule = "{$attribute}.".Str::snake(class_basename($lowerRule)); + $shortRule = "{$attribute}.".Str::snake(class_basename($lowerRule)); - if (! in_array($shortHandRule, $keys)) { - $keys[] = $shortHandRule; + if (! in_array($shortRule, $keys)) { + $keys[] = $shortRule; } // First we will check for a custom message for an attribute specific rule