Skip to content

Commit

Permalink
add event to make model validation extendable
Browse files Browse the repository at this point in the history
  • Loading branch information
mjauvin committed Jan 28, 2023
1 parent f9b9241 commit 4ff3c18
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,25 @@ public function setValidationAttributeName($attr, $name)
*/
protected function getValidationAttributes()
{
/**
* @event model.getValidationAttributes
* Called when fetching the model attributes to validate the model
*
* Example usage from TranslatableBehavior class:
*
* $model->bindEvent('model.getValidationAttributes', function() {
* $locale = $this->translateContext();
* if ($locale !== $this->translatableDefault) {
* $attributes = $this->model->getAttributes();
* return array_merge($attributes, $this->getTranslateDirty($locale));
* }
* });
*
*/
if ($attributes = $this->fireEvent('model.getValidationAttributes', [], true)) {
return $attributes;
}

return $this->getAttributes();
}

Expand Down

0 comments on commit 4ff3c18

Please sign in to comment.