eightyfive's avatar

Eloquent events not being registered (static::$dispatcher not set = null)

Hi,

I'm having troubled using spatie/laravel-activitylog, the events registering in their booLogsActivity trait doesn't happen cause Eloquent\Model::$dispatcher is not yet set at the time of trait booting: https://github.com/illuminate/database/blob/v5.3.23/Eloquent/Model.php#L1273

Somehow bootLogsActivity is called too soon, before the capsule has set up Eloquent: https://github.com/illuminate/database/blob/v5.3.23/DatabaseManager.php#L190

Any help/direction appreciated.

0 likes
2 replies
eightyfive's avatar
eightyfive
OP
Best Answer
Level 1

My bad. This had to do with my App\ code.

For further reference, if you face a similar issue, a good place to start from is: http://php.net/manual/fr/function.debug-backtrace.php

I guessed I was calling a Service too soon in my Application lifecycle and wanted to know where.

This helped me figuring out where I was calling $app->make( ... )/app( ... )/ ... too soon in my Application lifecycle.

You shouldn't use the Container::make method before all your App services have been registered correctly.

Hope this helps.

1 like
grantholle's avatar

I cannot tell you have big of a find this was 6 years later...

In my case I was doing something in the register function of a service provider when it should have been in the boot method. Using the backtrace tip I was able to find it immediately... In my case using ray()->backtrace().

Please or to participate in this conversation.