Skip to content

Commit

Permalink
Stop recycling the exiting validator
Browse files Browse the repository at this point in the history
When recycling the existing validator we run across issues
where the unique validation rule fails if you save and update
a model.
  • Loading branch information
Jaspaul committed Aug 29, 2017
1 parent f094797 commit dec7aa1
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/Traits/Validates.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,6 @@ protected function getMessages() : array
return [];
}

/**
* The validator.
*
* @return \Illuminate\Contracts\Validation\Validator
*/
private $validator;

/**
* Returns an instance of the validator from our container.
*
Expand All @@ -59,14 +52,11 @@ private function getValidationFactory() : Factory
*/
private function getValidator() : Validator
{
if (is_null($this->validator)) {
$this->validator = $this->getValidationFactory()->make(
$this->getData(),
$this->getRules(),
$this->getMessages()
);
}
return $this->validator;
return $this->getValidationFactory()->make(
$this->getData(),
$this->getRules(),
$this->getMessages()
);
}

/**
Expand Down Expand Up @@ -123,9 +113,12 @@ public function getErrors() : MessageProvider
*/
public function getValidationFailureReasons() : array
{
if ($this->isInvalid()) {
return $this->getValidator()->failed();
$validator = $this->getValidator();

if ($validator->fails()) {
return $validator->failed();
}

return [];
}

Expand Down

0 comments on commit dec7aa1

Please sign in to comment.