Replies: 3 comments
-
Can you recheck your Laravel version? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Yes of course, it is |
Beta Was this translation helpful? Give feedback.
0 replies
-
Hi, I'll also add this #53616 observation (I don't understand if it can be related, if it isn't I apologize). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Laravel Version
10.48.17
PHP Version
8.2
Description
Greetings,
In my project I use the following package to make my models archivable: Laravel Archivable
This package fires 4 new events to be used in the corresponding observer class. There is no problem using EventServiceProvider's
boot()
method to call model'sobserve
method or the$observers
property to register the observer, but it does not work as expected when using theObservedBy
attribute. This is because when theHasEvents
trait is booted, the observer is registered at that moment. Therefore, even if another bootable trait in the model calls theaddObservableEvents
method in the initialize method, it will have no effect. Because this operation is done after HasEvents has been booted, the observer is already registered.Steps To Reproduce
addObservableEvents
with custom model event names in initialize methodAll traits are looped in the order they are written then calling boot method.
The boot method calls the observe method directly at this point. But the custom trait has not yet been booted and initialised.
https://laravel.com/docs/10.x/eloquent#observers
....
Laravel documentation says you can use both. But they give different results for this situation.
Thank you in advance
Beta Was this translation helpful? Give feedback.
All reactions