-
Notifications
You must be signed in to change notification settings - Fork 11.5k
Add "trashed" event to $observables in SoftDeletes Trait #54987
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Added "trashed" event to $observables array so that subscribed Observers can catch the event.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should work
I am closing this pull request because it lacks sufficient explanation, tests, or both. It is difficult for us to merge pull requests without these things because the change may introduce breaking changes to the framework. Feel free to re-submit your change with a thorough explanation of the feature and tests - integration tests are preferred over unit tests. Please include it's benefit to end users; the reasons it does not break any existing features; how it makes building web applications easier, etc. Thanks! |
Sorry, you are right! I don't think it creates any breaking changes because it uses addObservableEvents() which just populates the $observables array property. The property is described as "User exposed observable events. These are extra user-defined events observers may subscribe to." so we not even reset it but just adding this new event to it (even though it is probably empty). The reason to add "trashed" event to it in SoftDeletes Trait initialization function is because on soft deletion of a model the "trashed" event is dispatched BUT the user will not be able to catch it with an observer because it is not registered. Here is part of the code responsible for registering observable events:
So only this observable events will be available to be registered with an observer. No "trashed" event which is available by SoftDeletes Trait when used. The reason for adding this event is because users might want to track activity log of a model with an observer and log actions like soft deleted, restored, created etc. Both forceDelete() and delete() fire "deleted" event and their respective events of "force deleted" and "trashed" but "trashed can't be listened to in an observer which i think is not intuitive or the desired feature. So it will be common sense for it to be available in an observer too, like someone would draw the conclusion from the docs.
Do i still need to create a test for this?! |
Fixes laravel#54980 Previous pull laravel#54987 but this one is more clear and inline.
Added "trashed" event to $observables array so that subscribed Observers can catch the event as Expected!