Laravel Eloquent model events suddenly not called

580 Views Asked by At

In my Laravel 5.3 application I am using several Eloquent model events (mostly creating). Up until a week ago they were working fine but suddenly as of today I notice that none of them seem to be firing anymore.

Debugging through the framework shows that they are indeed all added to the Dispatcher::listeners array, but I can't find the code that should step through and actually run them. Placing die() commands in the event callbacks do nothing, suggesting they are not acutally firing, and nothing I try seems to get them working.

Here is an example of one of them (this one is on a trait, but I am using a mix of traits and direct model):

public static function bootUuidModel() { // On create, generate and assign a UUID static::creating(function (Model $model) { $model->setAttribute(self::getUuidFieldKey(), Uuid::uuid4()->toString()); }); }

Anyone have any ideas as to why these are suddenly not running? I am using them across various models for various purposes and none of them seem to be running. Has anyone else using the framework experienced these problems as of late?

Thanks in advance

--UPDATE--

Okay so after some more investigation I've found that the problem is that the User object is for some reason booting BEFORE Laravel's DatabaseServiceProvider is booted. DatabaseServiceProvider::boot() for some reason is where the event dispatcher is statically assigned to Model. So any booting in the User object is not registering the events with the dispatcher because the dispatcher doesn't exist yet. I am not booting the User object myself, does anyone know why Laravel would be doing this?

0

There are 0 best solutions below