Skip to content

Commit fc896bd

Browse files
committed
Fix present rule ignoring other rules when field is empty
1 parent 0f1e7ba commit fc896bd

File tree

1 file changed

+18
-5
lines changed

1 file changed

+18
-5
lines changed

src/Rules/Present.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@
44

55
use IgniteKit\Validation\Rule;
66

7-
class Present extends Rule
8-
{
7+
class Present extends Rule {
98
/** @var bool */
109
protected $implicit = true;
1110

@@ -16,10 +15,24 @@ class Present extends Rule
1615
* Check the $value is valid
1716
*
1817
* @param mixed $value
18+
*
1919
* @return bool
2020
*/
21-
public function check($value): bool
22-
{
23-
return $this->validation->hasValue($this->attribute->getKey());
21+
public function check( $value ): bool {
22+
23+
$this->setAttributeAsRequired();
24+
25+
return $this->validation->hasValue( $this->attribute->getKey() );
26+
}
27+
28+
/**
29+
* Set attribute is required if $this->attribute is set
30+
*
31+
* @return void
32+
*/
33+
protected function setAttributeAsRequired() {
34+
if ( $this->attribute ) {
35+
$this->attribute->setRequired( true );
36+
}
2437
}
2538
}

0 commit comments

Comments
 (0)