Skip to content

Commit dec7aa1

Browse files
committed
Stop recycling the exiting validator
When recycling the existing validator we run across issues where the unique validation rule fails if you save and update a model.
1 parent f094797 commit dec7aa1

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

src/Traits/Validates.php

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,6 @@ protected function getMessages() : array
3434
return [];
3535
}
3636

37-
/**
38-
* The validator.
39-
*
40-
* @return \Illuminate\Contracts\Validation\Validator
41-
*/
42-
private $validator;
43-
4437
/**
4538
* Returns an instance of the validator from our container.
4639
*
@@ -59,14 +52,11 @@ private function getValidationFactory() : Factory
5952
*/
6053
private function getValidator() : Validator
6154
{
62-
if (is_null($this->validator)) {
63-
$this->validator = $this->getValidationFactory()->make(
64-
$this->getData(),
65-
$this->getRules(),
66-
$this->getMessages()
67-
);
68-
}
69-
return $this->validator;
55+
return $this->getValidationFactory()->make(
56+
$this->getData(),
57+
$this->getRules(),
58+
$this->getMessages()
59+
);
7060
}
7161

7262
/**
@@ -123,9 +113,12 @@ public function getErrors() : MessageProvider
123113
*/
124114
public function getValidationFailureReasons() : array
125115
{
126-
if ($this->isInvalid()) {
127-
return $this->getValidator()->failed();
116+
$validator = $this->getValidator();
117+
118+
if ($validator->fails()) {
119+
return $validator->failed();
128120
}
121+
129122
return [];
130123
}
131124

0 commit comments

Comments
 (0)