Skip to content

Triggers

Triggers are how workflows get started. Workflowable supports three ways to trigger workflow execution.

Trigger Types

TriggerDescription
Direct DispatchExplicit dispatch via the Workflowable facade. Full control over sync/async and return values.
Event-DrivenLaravel events auto-trigger workflows via the TriggersWorkflow interface. Zero configuration.
Scheduled (CRON)Database-driven schedules that dispatch workflows on a recurring basis.

Choosing a Trigger

Use CaseRecommended Trigger
Explicit API call or controller actionDirect Dispatch
Existing Laravel domain eventsEvent-Driven
Recurring tasks (reports, cleanups)Scheduled
Need the instance collection backDirect Dispatch
Fire-and-forget, zero couplingEvent-Driven
Time-based with duplicate preventionScheduled

Workflow Events

All triggers ultimately dispatch a WorkflowEvent DTO. This is the typed data carrier that workflows operate on:

php
use Workflowable\Workflowable\Abstracts\WorkflowEvent;

class OrderSubmitted extends WorkflowEvent
{
    public function __construct(
        public readonly int $orderId,
        public readonly float $amount,
        public readonly string $customerEmail,
    ) {}

    public static function encrypted(): array
    {
        return ['customerEmail'];
    }
}

Constructor parameters become workflow variables accessible via ExecutionContext::getVariable() in step handlers.