HasEvents
trait HasEvents (View source)
Properties
| protected array | $dispatchesEvents | The event map for the model. | |
| protected array | $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|array|string $classes)
Register observers with the model. | |
| void | registerObserver(object|string $class)
Register a single 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, QueuedClosure|Closure|string|array $callback)
Register a model event with the dispatcher. | |
| 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 | retrieved(QueuedClosure|Closure|string|array $callback)
Register a retrieved model event with the dispatcher. | |
| static void | saving(QueuedClosure|Closure|string|array $callback)
Register a saving model event with the dispatcher. | |
| static void | saved(QueuedClosure|Closure|string|array $callback)
Register a saved model event with the dispatcher. | |
| static void | updating(QueuedClosure|Closure|string|array $callback)
Register an updating model event with the dispatcher. | |
| static void | updated(QueuedClosure|Closure|string|array $callback)
Register an updated model event with the dispatcher. | |
| static void | creating(QueuedClosure|Closure|string|array $callback)
Register a creating model event with the dispatcher. | |
| static void | created(QueuedClosure|Closure|string|array $callback)
Register a created model event with the dispatcher. | |
| static void | replicating(QueuedClosure|Closure|string|array $callback)
Register a replicating model event with the dispatcher. | |
| static void | deleting(QueuedClosure|Closure|string|array $callback)
Register a deleting model event with the dispatcher. | |
| static void | deleted(QueuedClosure|Closure|string|array $callback)
Register a deleted model event with the dispatcher. | |
| static void | flushEventListeners()
Remove all the event listeners for the model. | |
| array | dispatchesEvents()
Get the event map 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. | |
| static mixed | withoutEvents(callable $callback)
Execute a callback without firing any model events for any model type. |
Details
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|array|string $classes)
Register observers with the model.
protected void registerObserver(object|string $class)
Register a single 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 protected void registerModelEvent(string $event, QueuedClosure|Closure|string|array $callback)
Register a model event with the dispatcher.
protected mixed fireModelEvent(string $event, bool $halt = true)
Fire the given event for the model.
protected mixed|null fireCustomModelEvent(string $event, string $method)
Fire a custom model event for the given event.
protected mixed filterModelEventResults(mixed $result)
Filter the model event results.
static void retrieved(QueuedClosure|Closure|string|array $callback)
Register a retrieved model event with the dispatcher.
static void saving(QueuedClosure|Closure|string|array $callback)
Register a saving model event with the dispatcher.
static void saved(QueuedClosure|Closure|string|array $callback)
Register a saved model event with the dispatcher.
static void updating(QueuedClosure|Closure|string|array $callback)
Register an updating model event with the dispatcher.
static void updated(QueuedClosure|Closure|string|array $callback)
Register an updated model event with the dispatcher.
static void creating(QueuedClosure|Closure|string|array $callback)
Register a creating model event with the dispatcher.
static void created(QueuedClosure|Closure|string|array $callback)
Register a created model event with the dispatcher.
static void replicating(QueuedClosure|Closure|string|array $callback)
Register a replicating model event with the dispatcher.
static void deleting(QueuedClosure|Closure|string|array $callback)
Register a deleting model event with the dispatcher.
static void deleted(QueuedClosure|Closure|string|array $callback)
Register a deleted model event with the dispatcher.
static void flushEventListeners()
Remove all the event listeners for the model.
array dispatchesEvents()
Get the event map 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.
static mixed withoutEvents(callable $callback)
Execute a callback without firing any model events for any model type.
© Taylor Otwell
Licensed under the MIT License.
Laravel is a trademark of Taylor Otwell.
https://laravel.com/api/11.x/Illuminate/Database/Eloquent/Concerns/HasEvents.html