Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Database/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,11 +226,14 @@ protected function bootNicerEvents()
}

self::$eventMethod(function ($model) use ($method) {
$model->fireEvent('model.' . $method);
$result = null;

if ($model->methodExists($method)) {
return $model->$method();
$result = $model->$method();
}
$model->fireEvent('model.' . $method);

return $result;
});
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/Database/Traits/SoftDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ public static function bootSoftDelete()
static::addGlobalScope(new SoftDeletingScope);

static::restoring(function ($model) {
if ($model->methodExists('beforeRestore')) {
$model->beforeRestore();
}
/**
* @event model.beforeRestore
* Called before the model is restored from a soft delete
Expand All @@ -36,12 +39,12 @@ public static function bootSoftDelete()
*
*/
$model->fireEvent('model.beforeRestore');
if ($model->methodExists('beforeRestore')) {
$model->beforeRestore();
}
});

static::restored(function ($model) {
if ($model->methodExists('afterRestore')) {
$model->afterRestore();
}
/**
* @event model.afterRestore
* Called after the model is restored from a soft delete
Expand All @@ -54,9 +57,6 @@ public static function bootSoftDelete()
*
*/
$model->fireEvent('model.afterRestore');
if ($model->methodExists('afterRestore')) {
$model->afterRestore();
}
});
}

Expand Down
16 changes: 8 additions & 8 deletions src/Database/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ public function validate($rules = null, $customMessages = null, $attributeNames
? $this->throwOnValidation
: true;

if ($this->methodExists('beforeValidate')) {
$this->beforeValidate();
}

/**
* @event model.beforeValidate
* Called before the model is validated
Expand All @@ -194,10 +198,6 @@ public function validate($rules = null, $customMessages = null, $attributeNames
return false;
}

if ($this->methodExists('beforeValidate')) {
$this->beforeValidate();
}

/*
* Perform validation
*/
Expand Down Expand Up @@ -323,6 +323,10 @@ public function validate($rules = null, $customMessages = null, $attributeNames
}
}

if ($this->methodExists('afterValidate')) {
$this->afterValidate();
}

/**
* @event model.afterValidate
* Called after the model is validated
Expand All @@ -337,10 +341,6 @@ public function validate($rules = null, $customMessages = null, $attributeNames
$this->fireModelEvent('validated', false);
$this->fireEvent('model.afterValidate');

if ($this->methodExists('afterValidate')) {
$this->afterValidate();
}

if (!$success && $throwOnValidation) {
throw new ModelException($this);
}
Expand Down
7 changes: 5 additions & 2 deletions src/Halcyon/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,11 +239,14 @@ protected function bootNicerEvents()
}

self::$eventMethod(function ($model) use ($method) {
$model->fireEvent('model.' . $method);
$result = null;

if ($model->methodExists($method)) {
return $model->$method();
$result = $model->$method();
}
$model->fireEvent('model.' . $method);

return $result;
});
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/Halcyon/Traits/Validation.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ public function validate($rules = null, $customMessages = null, $attributeNames
? $this->throwOnValidation
: true;

if ($this->methodExists('beforeValidate')) {
$this->beforeValidate();
}

if (($this->fireModelEvent('validating') === false) || ($this->fireEvent('model.beforeValidate') === false)) {
if ($throwOnValidation) {
throw new ModelException($this);
Expand All @@ -128,10 +132,6 @@ public function validate($rules = null, $customMessages = null, $attributeNames
return false;
}

if ($this->methodExists('beforeValidate')) {
$this->beforeValidate();
}

/*
* Perform validation
*/
Expand Down Expand Up @@ -209,13 +209,13 @@ public function validate($rules = null, $customMessages = null, $attributeNames
}
}

$this->fireModelEvent('validated', false);
$this->fireEvent('model.afterValidate');

if ($this->methodExists('afterValidate')) {
$this->afterValidate();
}

$this->fireModelEvent('validated', false);
$this->fireEvent('model.afterValidate');

if (!$success && $throwOnValidation) {
throw new ModelException($this);
}
Expand Down