Skip to content

Events Reference

Workflowable dispatches Laravel events at every workflow lifecycle point. Listen to these for notifications, logging, metrics, and integrations.

Event List

All events are in the Workflowable\Workflowable\Events namespace.

EventWhenProperties
WorkflowStartedWorkflow instance created$instance, $userId
StepStartedStep begins execution$execution
StepCompletedStep succeeds$execution, $result
StepRetryingStep about to retry$execution, $attempt, $delaySeconds
StepFailedStep fails$execution, $exception, $willRetry
TransitionTriggeredMoving to next step$instance, $fromStep, $toStep, $condition
WorkflowCompletedWorkflow finishes successfully$instance, $result
WorkflowFailedWorkflow fails$instance, $exception

Listening to Events

In a Service Provider

php
use Workflowable\Workflowable\Events\WorkflowCompleted;
use Workflowable\Workflowable\Events\StepFailed;

Event::listen(WorkflowCompleted::class, function ($event) {
    Log::info("Workflow completed: {$event->instance->id}");
});

Event::listen(StepFailed::class, function ($event) {
    if (!$event->willRetry) {
        AlertService::notify("Step failed permanently: {$event->execution->step_name}");
    }
});

As Listener Classes

php
// EventServiceProvider
protected $listen = [
    \Workflowable\Workflowable\Events\WorkflowCompleted::class => [
        \App\Listeners\LogWorkflowCompletion::class,
    ],
    \Workflowable\Workflowable\Events\StepFailed::class => [
        \App\Listeners\AlertOnStepFailure::class,
    ],
];

Common Patterns

Monitoring Failed Steps

php
Event::listen(StepFailed::class, function ($event) {
    if ($event->willRetry) {
        Log::warning("Step retrying", [
            'step' => $event->execution->step_name,
            'attempt' => $event->execution->attempts,
        ]);
    } else {
        Log::error("Step failed permanently", [
            'step' => $event->execution->step_name,
            'error' => $event->exception->getMessage(),
        ]);
    }
});

Tracking Workflow Metrics

php
Event::listen(WorkflowStarted::class, fn ($e) =>
    Metrics::increment('workflow.started', ['name' => $e->instance->workflow->name])
);

Event::listen(WorkflowCompleted::class, fn ($e) =>
    Metrics::increment('workflow.completed', ['name' => $e->instance->workflow->name])
);

Event::listen(WorkflowFailed::class, fn ($e) =>
    Metrics::increment('workflow.failed', ['name' => $e->instance->workflow->name])
);