From 9d02a850ef2ca506a3b31b76f3c36e2e583fae9c Mon Sep 17 00:00:00 2001 From: Mior Muhammad Zaki Date: Mon, 16 Aug 2021 17:31:33 +0800 Subject: [PATCH] [8.x] Use `Fluent` instead of `array` on `Rule::when()` Signed-off-by: Mior Muhammad Zaki --- src/Illuminate/Validation/ConditionalRules.php | 4 +++- tests/Validation/ValidationRuleParserTest.php | 3 ++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Validation/ConditionalRules.php b/src/Illuminate/Validation/ConditionalRules.php index f8352360b33a..1c8ea9dffc0b 100644 --- a/src/Illuminate/Validation/ConditionalRules.php +++ b/src/Illuminate/Validation/ConditionalRules.php @@ -2,6 +2,8 @@ namespace Illuminate\Validation; +use Illuminate\Support\Fluent; + class ConditionalRules { /** @@ -40,7 +42,7 @@ public function __construct($condition, $rules) public function passes(array $data = []) { return is_callable($this->condition) - ? call_user_func($this->condition, $data) + ? call_user_func($this->condition, new Fluent($data)) : $this->condition; } diff --git a/tests/Validation/ValidationRuleParserTest.php b/tests/Validation/ValidationRuleParserTest.php index dab4ec5c342f..48ab2be04938 100644 --- a/tests/Validation/ValidationRuleParserTest.php +++ b/tests/Validation/ValidationRuleParserTest.php @@ -2,6 +2,7 @@ namespace Illuminate\Tests\Validation; +use Illuminate\Support\Fluent; use Illuminate\Validation\Rule; use Illuminate\Validation\ValidationRuleParser; use PHPUnit\Framework\TestCase; @@ -16,7 +17,7 @@ public function test_conditional_rules_are_properly_expanded_and_filtered() 'password' => Rule::when(true, 'required|min:2'), 'username' => ['required', Rule::when(true, ['min:2'])], 'address' => ['required', Rule::when(false, ['min:2'])], - 'city' => ['required', Rule::when(function (array $input) { + 'city' => ['required', Rule::when(function (Fluent $input) { return true; }, ['min:2'])], ]);