Skip to content

Commit

Permalink
[8.x] Use Fluent instead of array on Rule::when()
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Aug 16, 2021
1 parent f95f3af commit 9d02a85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/Illuminate/Validation/ConditionalRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Illuminate\Validation;

use Illuminate\Support\Fluent;

class ConditionalRules
{
/**
Expand Down Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Validation/ValidationRuleParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Illuminate\Tests\Validation;

use Illuminate\Support\Fluent;
use Illuminate\Validation\Rule;
use Illuminate\Validation\ValidationRuleParser;
use PHPUnit\Framework\TestCase;
Expand All @@ -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'])],
]);
Expand Down

0 comments on commit 9d02a85

Please sign in to comment.