Projectslaravel-actionsEvents

Laravel Actions

Package

Synchronously dispatched action classes for Laravel.

Upgrade Guide

Events

Three lifecycle events are dispatched by the real dispatcher (including when execution is allowed under a fake):

EventWhen
ActionDispatchingBefore handle()
ActionDispatchedAfter a successful handle()
ActionFailedWhen handle() throws (exception is rethrown)
use BradieTilley\Actions\Events\ActionDispatched;
use BradieTilley\Actions\Events\ActionDispatching;
use BradieTilley\Actions\Events\ActionFailed;
use Illuminate\Support\Facades\Event;

Event::listen(ActionDispatching::class, function (ActionDispatching $event) {
    // $event->action
});

Event::listen(ActionDispatched::class, function (ActionDispatched $event) {
    // $event->action
    // $event->value
    // $event->duration  // BradieTilley\Actions\Duration
});

Event::listen(ActionFailed::class, function (ActionFailed $event) {
    // $event->action
    // $event->error
});

Duration

ActionDispatched::$duration is a BradieTilley\Actions\Duration value object with asNanoseconds(), asMicroseconds(), asMilliseconds(), asSeconds(), and __toString().

Continue to Extensibility.