Skip to content

Commit

Permalink
Allow forcing validation via the public property
Browse files Browse the repository at this point in the history
  • Loading branch information
daftspunk committed Mar 7, 2024
1 parent ea3fa78 commit 84bf798
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,18 +70,24 @@ public function initializeValidation()
}

$this->bindEvent('model.saveInternal', function() {
$validationForced = $this->validationForced;

if (($forceOption = $this->getSaveOption('force')) !== null) {
$this->validationForced = $forceOption;
}

// If forcing the save event, the beforeValidate/afterValidate
// events should still fire for consistency. So validate an
// empty set of rules and messages.
$this->validationForced = $this->getSaveOption('force', false);

if ($this->validationForced) {
$valid = $this->validate([], []);
}
else {
$valid = $this->validate();
}

$this->validationForced = $validationForced;

if (!$valid) {
return false;
}
Expand Down

0 comments on commit 84bf798

Please sign in to comment.