trait HasEvents

Properties

protected array $dispatchesEvents

The event map for the model.

protected array $observables

User exposed observable events.

Methods

static void
observe(object|string $class)

Register an observer with the Model.

array
getObservableEvents()

Get the observable event names.

$this
setObservableEvents(array $observables)

Set the observable event names.

void
addObservableEvents(array|mixed $observables)

Add an observable event name.

void
removeObservableEvents(array|mixed $observables)

Remove an observable event name.

static void
registerModelEvent(string $event, Closure|string $callback, int $priority = 0)

Register a model event with the dispatcher.

bootNicerEvents()

Bind some nicer events to this model, in the format of method overrides.

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

Fire the given event for the model.

mixed|null
fireCustomModelEvent(string $event, string $method)

Fire a custom model event for the given event.

mixed
filterModelEventResults(mixed $result)

Filter the model event results.

static void
retrieving(Closure|string $callback)

Create a new native event for handling beforeFetch().

static void
retrieved(Closure|string $callback)

Register a retrieved model event with the dispatcher.

static void
saving(Closure|string $callback, int $priority = 0)

Register a saving model event with the dispatcher.

static void
saved(Closure|string $callback, int $priority = 0)

Register a saved model event with the dispatcher.

static void
updating(Closure|string $callback, int $priority = 0)

Register an updating model event with the dispatcher.

static void
updated(Closure|string $callback, int $priority = 0)

Register an updated model event with the dispatcher.

static void
creating(Closure|string $callback, int $priority = 0)

Register a creating model event with the dispatcher.

static void
created(Closure|string $callback, int $priority = 0)

Register a created model event with the dispatcher.

static void
deleting(Closure|string $callback, int $priority = 0)

Register a deleting model event with the dispatcher.

static void
deleted(Closure|string $callback, int $priority = 0)

Register a deleted model event with the dispatcher.

static void
flushEventListeners()

Remove all of the event listeners for the model.

static Dispatcher
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.

Details

at line 34
static void observe(object|string $class)

Register an observer with the Model.

Parameters

object|string $class

Return Value

void

at line 55
array getObservableEvents()

Get the observable event names.

Return Value

array

at line 74
$this setObservableEvents(array $observables)

Set the observable event names.

Parameters

array $observables

Return Value

$this

at line 88
void addObservableEvents(array|mixed $observables)

Add an observable event name.

Parameters

array|mixed $observables

Return Value

void

at line 102
void removeObservableEvents(array|mixed $observables)

Remove an observable event name.

Parameters

array|mixed $observables

Return Value

void

at line 118
static protected void registerModelEvent(string $event, Closure|string $callback, int $priority = 0)

Register a model event with the dispatcher.

Parameters

string $event
Closure|string $callback
int $priority

Return Value

void

at line 130
protected bootNicerEvents()

Bind some nicer events to this model, in the format of method overrides.

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

Fire the given event for the model.

Parameters

string $event
bool $halt

Return Value

mixed

at line 209
protected mixed|null fireCustomModelEvent(string $event, string $method)

Fire a custom model event for the given event.

Parameters

string $event
string $method

Return Value

mixed|null

at line 229
protected mixed filterModelEventResults(mixed $result)

Filter the model event results.

Parameters

mixed $result

Return Value

mixed

at line 247
static void retrieving(Closure|string $callback)

Create a new native event for handling beforeFetch().

Parameters

Closure|string $callback

Return Value

void

at line 259
static void retrieved(Closure|string $callback)

Register a retrieved model event with the dispatcher.

Parameters

Closure|string $callback

Return Value

void

at line 272
static void saving(Closure|string $callback, int $priority = 0)

Register a saving model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 285
static void saved(Closure|string $callback, int $priority = 0)

Register a saved model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 298
static void updating(Closure|string $callback, int $priority = 0)

Register an updating model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 311
static void updated(Closure|string $callback, int $priority = 0)

Register an updated model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 324
static void creating(Closure|string $callback, int $priority = 0)

Register a creating model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 337
static void created(Closure|string $callback, int $priority = 0)

Register a created model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 350
static void deleting(Closure|string $callback, int $priority = 0)

Register a deleting model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 363
static void deleted(Closure|string $callback, int $priority = 0)

Register a deleted model event with the dispatcher.

Parameters

Closure|string $callback
int $priority

Return Value

void

at line 373
static void flushEventListeners()

Remove all of the event listeners for the model.

Return Value

void

at line 391
static Dispatcher getEventDispatcher()

Get the event dispatcher instance.

Return Value

Dispatcher

at line 403
static void setEventDispatcher(Dispatcher $dispatcher)

Set the event dispatcher instance.

Parameters

Dispatcher $dispatcher

Return Value

void

at line 413
static void unsetEventDispatcher()

Unset the event dispatcher for models.

Return Value

void