Skip to content

[5.4] Model event result prevents firing observable events#18401

Merged
taylorotwell merged 2 commits into
laravel:5.4from
thijskok:fix-blocking-eloquent-events
Mar 18, 2017
Merged

[5.4] Model event result prevents firing observable events#18401
taylorotwell merged 2 commits into
laravel:5.4from
thijskok:fix-blocking-eloquent-events

Conversation

@thijskok

Copy link
Copy Markdown
Contributor

When a model uses the $event property as well as observable events (e.g., through a 3rd party package), sometimes event handling will stop before reaching the observables. This is because the model's event result is treated as "failed" in Illuminate/Database/Eloquent/Concerns/HasEvents.php, while it isn't:

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

// ...
// For example, one event listener running successfully 
// causes the $result variable to be array(0 => null)
// ...

return ! empty($result) ? $result : static::$dispatcher->{$method}(
    "eloquent.{$event}: ".static::class, $this
);

Empty evaluates the array containing null as false, preventing the dispatcher from firing any subsequent events. The code fragment in this PR strips out the null elements, causing empty to be true when model events were handled successfully.

@taylorotwell taylorotwell merged commit 9eee1fe into laravel:5.4 Mar 18, 2017
@thijskok thijskok deleted the fix-blocking-eloquent-events branch June 10, 2019 20:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants