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'])], ]);