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 41
static void
bootHasEvents()
Boot the has event trait for a model.
at line 57
static array
resolveObserveAttributes()
Resolve the observe class names from the attributes.
at line 88
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 104
protected void
registerObserver(object|string $class)
Register a single observer with the model.
at line 144
array
getObservableEvents()
Get the observable event names.
at line 162
HasEvents
setObservableEvents(array $observables)
Set the observable event names.
at line 174
void
addObservableEvents(array|string $observables)
Add an observable event name.
at line 187
void
removeObservableEvents(array|string $observables)
Remove an observable event name.
at line 200
static protected void
registerModelEvent(string $event, mixed $callback)
Register a model event with the dispatcher.
at line 212
protected mixed
fireModelEvent(string $event, bool $halt = true)
Fire the given event for the model.
at line 242
protected mixed
fireCustomModelEvent(string $event, string $method)
Fire a custom model event for the given event.
at line 260
protected mixed
filterModelEventResults(mixed $result)
Filter the model event results.
at line 278
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 292
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 306
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 320
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 334
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 348
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 362
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 376
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 390
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 404
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 415
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 437
array
dispatchesEvents()
Get the event map for the model.
at line 448
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 463
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 474
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 490
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 505
static bool
eventsDisabled()
Determine if model events are currently disabled for this coroutine.