trait HasEvents (View source)

Properties

protected array<string,class-string> $dispatchesEvents

The event map for the model.

protected string[] $observables

User exposed observable events.

Methods

static void
bootHasEvents()

Boot the has event trait for a model.

static array
resolveObserveAttributes()

Resolve the observe class names from the attributes.

static void
observe(object|string[]|string $classes)

Register observers with the model.

void
registerObserver(object|string $class)

Register a single observer with the model.

string[]
getObservableEvents()

Get the observable event names.

$this
setObservableEvents(array $observables)

Set the observable event names.

void
addObservableEvents(string|string[] $observables)

Add an observable event name.

void
removeObservableEvents(string|string[] $observables)

Remove an observable event name.

static void
registerModelEvent(string $event, QueuedClosure|callable|array|class-string $callback)

Register a model event with the dispatcher.

mixed
fireModelEvent(string $event, bool $halt = true)

Fire the given event for the model.

array|null|void
fireCustomModelEvent(string $event, $method)

Fire a custom model event for the given event.

mixed
filterModelEventResults(mixed $result)

Filter the model event results.

static void
retrieved(QueuedClosure|callable|array|class-string $callback)

Register a retrieved model event with the dispatcher.

static void
saving(QueuedClosure|callable|array|class-string $callback)

Register a saving model event with the dispatcher.

static void
saved(QueuedClosure|callable|array|class-string $callback)

Register a saved model event with the dispatcher.

static void
updating(QueuedClosure|callable|array|class-string $callback)

Register an updating model event with the dispatcher.

static void
updated(QueuedClosure|callable|array|class-string $callback)

Register an updated model event with the dispatcher.

static void
creating(QueuedClosure|callable|array|class-string $callback)

Register a creating model event with the dispatcher.

static void
created(QueuedClosure|callable|array|class-string $callback)

Register a created model event with the dispatcher.

static void
replicating(QueuedClosure|callable|array|class-string $callback)

Register a replicating model event with the dispatcher.

static void
deleting(QueuedClosure|callable|array|class-string $callback)

Register a deleting model event with the dispatcher.

static void
deleted(QueuedClosure|callable|array|class-string $callback)

Register a deleted model event with the dispatcher.

static void
flushEventListeners()

Remove all the event listeners for the model.

array<string,class-string>
dispatchesEvents()

Get the event map for the model.

static Dispatcher|null
getEventDispatcher()

Get the event dispatcher instance.

static void
setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

static void
unsetEventDispatcher()

Unset the event dispatcher for models.

static 
withoutEvents(callable $callback)

No description

Details

static void bootHasEvents()

Boot the has event trait for a model.

Return Value

void

static array resolveObserveAttributes()

Resolve the observe class names from the attributes.

Return Value

array

static void observe(object|string[]|string $classes)

Register observers with the model.

Parameters

object|string[]|string $classes

Return Value

void

Exceptions

RuntimeException

protected void registerObserver(object|string $class)

Register a single observer with the model.

Parameters

object|string $class

Return Value

void

Exceptions

RuntimeException

string[] getObservableEvents()

Get the observable event names.

Return Value

string[]

$this setObservableEvents(array $observables)

Set the observable event names.

Parameters

array $observables

Return Value

$this

void addObservableEvents(string|string[] $observables)

Add an observable event name.

Parameters

string|string[] $observables

Return Value

void

void removeObservableEvents(string|string[] $observables)

Remove an observable event name.

Parameters

string|string[] $observables

Return Value

void

static protected void registerModelEvent(string $event, QueuedClosure|callable|array|class-string $callback)

Register a model event with the dispatcher.

Parameters

string $event
QueuedClosure|callable|array|class-string $callback

Return Value

void

protected mixed fireModelEvent(string $event, bool $halt = true)

Fire the given event for the model.

Parameters

string $event
bool $halt

Return Value

mixed

protected array|null|void fireCustomModelEvent(string $event, $method)

Fire a custom model event for the given event.

Parameters

string $event
$method

Return Value

array|null|void

protected mixed filterModelEventResults(mixed $result)

Filter the model event results.

Parameters

mixed $result

Return Value

mixed

static void retrieved(QueuedClosure|callable|array|class-string $callback)

Register a retrieved model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void saving(QueuedClosure|callable|array|class-string $callback)

Register a saving model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void saved(QueuedClosure|callable|array|class-string $callback)

Register a saved model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void updating(QueuedClosure|callable|array|class-string $callback)

Register an updating model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void updated(QueuedClosure|callable|array|class-string $callback)

Register an updated model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void creating(QueuedClosure|callable|array|class-string $callback)

Register a creating model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void created(QueuedClosure|callable|array|class-string $callback)

Register a created model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void replicating(QueuedClosure|callable|array|class-string $callback)

Register a replicating model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void deleting(QueuedClosure|callable|array|class-string $callback)

Register a deleting model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void deleted(QueuedClosure|callable|array|class-string $callback)

Register a deleted model event with the dispatcher.

Parameters

QueuedClosure|callable|array|class-string $callback

Return Value

void

static void flushEventListeners()

Remove all the event listeners for the model.

Return Value

void

array<string,class-string> dispatchesEvents()

Get the event map for the model.

Return Value

array<string,class-string>

static Dispatcher|null getEventDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher|null

static void setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

Parameters

Dispatcher $dispatcher

Return Value

void

static void unsetEventDispatcher()

Unset the event dispatcher for models.

Return Value

void

static withoutEvents(callable $callback)

No description

Parameters

callable $callback