Skip to content

Commit 82afad6

Browse files
committed
Resolve observer attributes after booting has finished
- This ensure that all custom events have been registered by any traits first. - It also prevents a new instance of the model from being created by the call to `observe` too early, since an instance created before booting has finished would be in an inconsistent state due to not all of the trait boot methods being run yet and not all of the initializer methods would be registered yet, so they would not be run either.
1 parent 044cb93 commit 82afad6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ trait HasEvents
3838
*/
3939
public static function bootHasEvents()
4040
{
41-
static::observe(static::resolveObserveAttributes());
41+
static::registerModelEvent('booted', function () {
42+
static::observe(static::resolveObserveAttributes());
43+
});
4244
}
4345

4446
/**

0 commit comments

Comments
 (0)