Skip to content

Commit

Permalink
Wait for the dispatcher to be set before booting model events
Browse files Browse the repository at this point in the history
This fixes an issue that occurs when a model class is instantiated before the DatabaseServiceProvider can be booted (thus calling Model::setEventDispatcher()). Previously Winter would proceed with booting the nicer events, and then helpfully set a flag the events for the current model class had already been booted; however this would cause any and all "nice" model events to fail since they were never actually registered with an event dispatcher since Laravel silently discarded the required listeners when the $dispatcher property wasn't set.
LukeTowers authored Mar 14, 2022

Verified

This commit was signed with the committer’s verified signature.
joshcooper Josh Cooper
1 parent b977610 commit c76f1fa
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/Database/Model.php
Original file line number Diff line number Diff line change
@@ -143,6 +143,13 @@ protected function bootNicerEvents()
{
$class = get_called_class();

// If the $dispatcher hasn't been set yet don't bother trying
// to register the nicer model events yet since it will silently fail
if (!isset(static::$dispatcher)) {
return;
}

// Events have already been booted, continue
if (isset(static::$eventsBooted[$class])) {
return;
}

0 comments on commit c76f1fa

Please sign in to comment.