Skip to content

Commit ae63ff4

Browse files
authored
[8.x] Use Fluent instead of array on Rule::when() (#38397)
Signed-off-by: Mior Muhammad Zaki <[email protected]>
1 parent f95f3af commit ae63ff4

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/Illuminate/Validation/ConditionalRules.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
namespace Illuminate\Validation;
44

5+
use Illuminate\Support\Fluent;
6+
57
class ConditionalRules
68
{
79
/**
@@ -40,7 +42,7 @@ public function __construct($condition, $rules)
4042
public function passes(array $data = [])
4143
{
4244
return is_callable($this->condition)
43-
? call_user_func($this->condition, $data)
45+
? call_user_func($this->condition, new Fluent($data))
4446
: $this->condition;
4547
}
4648

tests/Validation/ValidationRuleParserTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Illuminate\Tests\Validation;
44

5+
use Illuminate\Support\Fluent;
56
use Illuminate\Validation\Rule;
67
use Illuminate\Validation\ValidationRuleParser;
78
use PHPUnit\Framework\TestCase;
@@ -16,7 +17,7 @@ public function test_conditional_rules_are_properly_expanded_and_filtered()
1617
'password' => Rule::when(true, 'required|min:2'),
1718
'username' => ['required', Rule::when(true, ['min:2'])],
1819
'address' => ['required', Rule::when(false, ['min:2'])],
19-
'city' => ['required', Rule::when(function (array $input) {
20+
'city' => ['required', Rule::when(function (Fluent $input) {
2021
return true;
2122
}, ['min:2'])],
2223
]);

0 commit comments

Comments
 (0)