Skip to content

Commit

Permalink
extract method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Mar 18, 2017
1 parent 9eee1fe commit 0607db0
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions src/Illuminate/Database/Eloquent/Concerns/HasEvents.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,18 +136,14 @@ protected function fireModelEvent($event, $halt = true)
// returns a result we can return that result, or we'll call the string events.
$method = $halt ? 'until' : 'fire';

$result = $this->fireCustomModelEvent($event, $method);
$result = $this->filterModelEventResults(
$this->fireCustomModelEvent($event, $method)
);

if ($result === false) {
return false;
}

if (is_array($result)) {
$result = array_filter($result, function ($response) {
return ! is_null($response);
});
}

return ! empty($result) ? $result : static::$dispatcher->{$method}(
"eloquent.{$event}: ".static::class, $this
);
Expand All @@ -173,6 +169,23 @@ protected function fireCustomModelEvent($event, $method)
}
}

/**
* Filter the model event results.
*
* @param mixed $result
* @return mixed
*/
protected function filterModelEventResults($result)
{
if (is_array($result)) {
$result = array_filter($result, function ($response) {
return ! is_null($response);
});
}

return $result;
}

/**
* Register a saving model event with the dispatcher.
*
Expand Down

0 comments on commit 0607db0

Please sign in to comment.