HasEvents
trait HasEvents
Properties
| protected array<string, class-string> | $dispatchesEvents | The event map for the model. |
|
| protected string[] | $observables | User exposed observable events. |
Methods
Boot the has event trait for a model.
Resolve the observe class names from the attributes.
Register observers with the model.
Register a single observer with the model.
Get the observable event names.
Set the observable event names.
Add an observable event name.
Remove an observable event name.
Register a model event with the dispatcher.
Fire the given event for the model.
Fire a custom model event for the given event.
Filter the model event results.
Register a retrieved model event with the dispatcher.
Register a saving model event with the dispatcher.
Register a saved model event with the dispatcher.
Register an updating model event with the dispatcher.
Register an updated model event with the dispatcher.
Register a creating model event with the dispatcher.
Register a created model event with the dispatcher.
Register a replicating model event with the dispatcher.
Register a deleting model event with the dispatcher.
Register a deleted model event with the dispatcher.
Remove all the event listeners for the model.
Get the event map for the model.
Get the event dispatcher instance.
Unset the event dispatcher for models.
Execute a callback without firing any model events for any model type.
Determine if model events are currently disabled for this coroutine.
Details
at line 40
static void
bootHasEvents()
Boot the has event trait for a model.
at line 56
static array
resolveObserveAttributes()
Resolve the observe class names from the attributes.
at line 87
static void
observe(object|array|string $classes)
Register observers with the model.
Boot-only. Observer listeners are registered on the worker-wide event dispatcher and persist for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 103
protected void
registerObserver(object|string $class)
Register a single observer with the model.
at line 143
array
getObservableEvents()
Get the observable event names.
at line 161
HasEvents
setObservableEvents(array $observables)
Set the observable event names.
at line 173
void
addObservableEvents(array|string $observables)
Add an observable event name.
at line 186
void
removeObservableEvents(array|string $observables)
Remove an observable event name.
at line 199
static protected void
registerModelEvent(string $event, mixed $callback)
Register a model event with the dispatcher.
at line 211
protected mixed
fireModelEvent(string $event, bool $halt = true)
Fire the given event for the model.
at line 241
protected mixed
fireCustomModelEvent(string $event, string $method)
Fire a custom model event for the given event.
at line 259
protected mixed
filterModelEventResults(mixed $result)
Filter the model event results.
at line 277
static void
retrieved(mixed $callback)
Register a retrieved model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 291
static void
saving(mixed $callback)
Register a saving model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 305
static void
saved(mixed $callback)
Register a saved model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 319
static void
updating(mixed $callback)
Register an updating model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 333
static void
updated(mixed $callback)
Register an updated model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 347
static void
creating(mixed $callback)
Register a creating model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 361
static void
created(mixed $callback)
Register a created model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 375
static void
replicating(mixed $callback)
Register a replicating model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 389
static void
deleting(mixed $callback)
Register a deleting model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 403
static void
deleted(mixed $callback)
Register a deleted model event with the dispatcher.
Boot-only. Listener persists on the worker-wide event dispatcher for the worker lifetime; runtime use leaks listeners across every subsequent request.
at line 414
static void
flushEventListeners()
Remove all the event listeners for the model.
Boot or tests only. Removes listeners from the worker-wide event dispatcher; concurrent coroutines lose model events mid-request.
at line 436
array
dispatchesEvents()
Get the event map for the model.
at line 447
static Dispatcher|null
getEventDispatcher()
Get the event dispatcher instance.
Returns a NullDispatcher when events are disabled (inside withoutEvents()) to ensure manual dispatch() calls are also suppressed, matching Laravel behavior.
at line 462
static void
setEventDispatcher(Dispatcher $dispatcher)
Set the event dispatcher instance.
Boot-only. The dispatcher persists in a static property for the worker lifetime and is used by every model event firing across all coroutines.
at line 473
static void
unsetEventDispatcher()
Unset the event dispatcher for models.
Tests only. Clears the worker-wide event dispatcher shared by every coroutine; concurrent model operations will not fire events.
at line 489
static mixed
withoutEvents(callable $callback)
Execute a callback without firing any model events for any model type.
Uses Context for coroutine-safe event disabling, ensuring concurrent requests don't interfere with each other's event handling.
at line 504
static bool
eventsDisabled()
Determine if model events are currently disabled for this coroutine.