Homepage
Main navigation
Main content
Additional information
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Winter CMS resources and help articles
Simple and to the point. Optimized by the community.
×
Login / Sign up
Quality Guidelines
About
GitHub
Propose new content
Edit trick
Changes will be published after manual review
Title
Give your trick a describing title. Do
not
start with «How to...».
Your trick
Keep it short and concise! Markdown is supported.
Laravel has a nice way of registering an Observer class to manage Model events: You can monitor all Laravel events: retrieved, creating, created, updating, updated, saving, saved, restoring, restored, replicating, deleting, deleted, forceDeleting, forceDeleted First, create an Observer class like this: ```php class MyModelObserver { public function created($model) { ... } public function updated($model) { ... } public function deleted($model) { ... } } ``` Then, simply register the Observer class with your model(s) in the `boot()` method of your plugin: ```php public function boot() { MyModel::observe(MyModelObserver::class); } ``` An Observer class may be used by multiple models if needed: ```php public function boot() { MyModel::observe(MyModelObserver::class); MyOtherModel::observe(MyModelObserver::class); } ``` You can also add multiple Oberver classes to a model: ```php public function boot() { MyModel::observe([Observer1::class, Observer2::class, ...]); } ```
References
Add additional online resources to your trick
+ Add reference
Topics
If your trick fits more than one topic select multiple. Select at least one.
Backend
Plugin Development
CMS
Twig
Themes
Deployment
Tags
You can use existing tags or create new ones. Add at least one.
Submit for review
Cancel
We use cookies to measure the performance of this website. Do you want to accept these cookies?
Accept
Decline