Skip to content

Added the missing 'trashed' event to getObservablesEvents()#55004

Merged
taylorotwell merged 1 commit into
laravel:12.xfrom
duemti:12.x
Mar 13, 2025
Merged

Added the missing 'trashed' event to getObservablesEvents()#55004
taylorotwell merged 1 commit into
laravel:12.xfrom
duemti:12.x

Conversation

@duemti

@duemti duemti commented Mar 13, 2025

Copy link
Copy Markdown
Contributor

Fixes #54980

I genuinely think this event was somehow forgot to be added there already.

Added the missing 'trashed' which gets registered with observers, so that observers too can listen to it besides listeners.
As per docs:

Eloquent models dispatch several events, allowing you to hook into the following moments in a model's lifecycle: retrieved, creating, created, updating, updated, saving, saved, deleting, deleted, trashed, forceDeleting, forceDeleted, restoring, restored, and replicating.

No breaking changes.

From the docs developers expect to listen to this event but if one uses observers then by default the observer would not be able catch it because it never was registered. This forced developers to redeclare the $observables in the model but this event belongs to the framework so it should not be missing by default from the already hard-coded event names array in getObservablesEvents().

No tests.

Fixes laravel#54980

Previous pull laravel#54987 but this one is more clear and inline.
@crynobone

Copy link
Copy Markdown
Member

No, only documentation for Observer should be updated to cover the different events available.

@duemti

duemti commented Mar 13, 2025

Copy link
Copy Markdown
Contributor Author

So you are saying that this event should not be available in observers by default?
Can i ask the reason?

@taylorotwell taylorotwell merged commit 5db13c7 into laravel:12.x Mar 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Observer does not listen to "trashed" event from Model

3 participants