Events
Lift provides three attributes to help you manage your model's events.
Listener
The Listener
attribute allows you to register a listener function for model events.
A more convenient way of registering a listener function "replacing" laravels event closures for eloquent models, more info Laravel Docs: Eloquent Closures
API
event
needs to be one of Laravel's model event e.g: 'created', 'creating', 'updated'. If you set queue
to true your handler will be executed async by Laravel's queue system.
โ ๏ธ If your function name is equal to the event name prefixed with "on" like onSaving or onDelete you don't need to specify the event name with the
Listener
Attribute
Observer
The Observer
attribute allows you to register a observer class for model events.
This is used to register a Observer Class with a model explained in more detail here: Laravel Docs: Eloquent Observers
API
With this attribute you can register a observer
to your model, in theory you could register as many observer classes as you want.
Dispatches
The Dispatches
attribute allows you to dispatch custom Laravel Events.
API
event
needs to be one of Laravel's model event e.g: 'created', 'creating', 'updated', but is optional if your eventClass
contains the event string in its name like ProductSaved
, saved
will be interpreted as the event.
Last updated