Skip to content

Commit 3289d7d

Browse files
committed
Fix rule same on array attribute
1 parent f091bf6 commit 3289d7d

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Rules/Same.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public function check($value)
1616
$this->requireParameters($this->fillable_params);
1717

1818
$field = $this->parameter('field');
19-
$anotherValue = $this->validation->getValue($field);
19+
$anotherValue = $this->getAttribute()->getValue($field);
2020

2121
return $value == $anotherValue;
2222
}

tests/ValidatorTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,4 +876,28 @@ public function testRequiredUnlessOnArrayAttribute()
876876
$this->assertNotNull($errors->first('products.14.notes'));
877877
}
878878

879+
public function testSameRuleOnArrayAttribute()
880+
{
881+
$validation = $this->validator->validate([
882+
'users' => [
883+
[
884+
'password' => 'foo',
885+
'password_confirmation' => 'foo'
886+
],
887+
[
888+
'password' => 'foo',
889+
'password_confirmation' => 'bar'
890+
],
891+
]
892+
], [
893+
'users.*.password_confirmation' => 'required|same:users.*.password',
894+
]);
895+
896+
$this->assertFalse($validation->passes());
897+
898+
$errors = $validation->errors();
899+
$this->assertNull($errors->first('users.0.password_confirmation:same'));
900+
$this->assertNotNull($errors->first('users.1.password_confirmation:same'));
901+
}
902+
879903
}

0 commit comments

Comments
 (0)