Skip to content

Commit a791e83

Browse files
committed
Refactor save into validate and save
1 parent 5856d41 commit a791e83

File tree

1 file changed

+16
-4
lines changed

1 file changed

+16
-4
lines changed

src/Traits/Validates.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,21 @@ public function isInvalid() : bool
8181
return $this->getValidator()->fails();
8282
}
8383

84+
/**
85+
* Used to validate the model.
86+
*
87+
* @throws \Illuminate\Validation\ValidationException
88+
* Thrown if the model is not valid.
89+
*
90+
* @return void
91+
*/
92+
public function validate() : void
93+
{
94+
if ($this->isInvalid()) {
95+
throw new ValidationException($this->getValidator());
96+
}
97+
}
98+
8499
/**
85100
* Returns a Message Provider containing the errors for the model validation.
86101
*
@@ -104,10 +119,7 @@ public function getErrors() : MessageProvider
104119
*/
105120
public function save(array $options = [])
106121
{
107-
if ($this->isInvalid()) {
108-
throw new ValidationException($this->getValidator());
109-
}
110-
122+
$this->validate();
111123
return parent::save($options);
112124
}
113125
}

0 commit comments

Comments
 (0)