Triggers
Triggers are how workflows get started. Workflowable supports three ways to trigger workflow execution.
Trigger Types
| Trigger | Description |
|---|---|
| Direct Dispatch | Explicit dispatch via the Workflowable facade. Full control over sync/async and return values. |
| Event-Driven | Laravel 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 Case | Recommended Trigger |
|---|---|
| Explicit API call or controller action | Direct Dispatch |
| Existing Laravel domain events | Event-Driven |
| Recurring tasks (reports, cleanups) | Scheduled |
| Need the instance collection back | Direct Dispatch |
| Fire-and-forget, zero coupling | Event-Driven |
| Time-based with duplicate prevention | Scheduled |
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.