Overview
Unleash Commerce uses observers to provide behavior that should always happen to models. For example, theUserObserver automatically removes roles and permissions when a user is deleted, ensuring data consistency without requiring manual cleanup.
Creating an Observer
Create an observer class and implement the observer contract for your model:Replacing an Observer
Replace a default observer with your custom implementation in a service provider:Disabling an Observer
Disable an observer entirely without replacing it in a service provider:Existing Observers
The core package includes the following observers:| Observer | Contract | Purpose |
|---|---|---|
CategoryObserver | CategoryObserverContract | Handles category deletion, including nested categories. |
UserObserver | UserObserverContract | Manages user deletion by cleaning up associated customer user relationships. |