Skip to content

Commit 0607db0

Browse files
committed
extract method
1 parent 9eee1fe commit 0607db0

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

src/Illuminate/Database/Eloquent/Concerns/HasEvents.php

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -136,18 +136,14 @@ protected function fireModelEvent($event, $halt = true)
136136
// returns a result we can return that result, or we'll call the string events.
137137
$method = $halt ? 'until' : 'fire';
138138

139-
$result = $this->fireCustomModelEvent($event, $method);
139+
$result = $this->filterModelEventResults(
140+
$this->fireCustomModelEvent($event, $method)
141+
);
140142

141143
if ($result === false) {
142144
return false;
143145
}
144146

145-
if (is_array($result)) {
146-
$result = array_filter($result, function ($response) {
147-
return ! is_null($response);
148-
});
149-
}
150-
151147
return ! empty($result) ? $result : static::$dispatcher->{$method}(
152148
"eloquent.{$event}: ".static::class, $this
153149
);
@@ -173,6 +169,23 @@ protected function fireCustomModelEvent($event, $method)
173169
}
174170
}
175171

172+
/**
173+
* Filter the model event results.
174+
*
175+
* @param mixed $result
176+
* @return mixed
177+
*/
178+
protected function filterModelEventResults($result)
179+
{
180+
if (is_array($result)) {
181+
$result = array_filter($result, function ($response) {
182+
return ! is_null($response);
183+
});
184+
}
185+
186+
return $result;
187+
}
188+
176189
/**
177190
* Register a saving model event with the dispatcher.
178191
*

0 commit comments

Comments
 (0)