Direct Dispatch
The most explicit way to trigger workflows. Use the Workflowable facade to dispatch a WorkflowEvent DTO directly.
Async Dispatch
Dispatches ExecuteWorkflowJob to the queue for each matching workflow:
php
use Workflowable\Workflowable\Facades\Workflowable;
$event = new \App\WorkflowEvents\OrderSubmitted(
orderId: 123,
amount: 1500.00,
customerEmail: 'customer@example.com',
);
// Returns Collection<WorkflowInstance>
$instances = Workflowable::dispatch($event);One event can trigger multiple workflows if more than one active workflow is bound to the same event_name.
Sync Dispatch
Executes inline, blocking until each workflow reaches completion:
php
$instances = Workflowable::dispatchSync($event);Use sync dispatch when you need the result immediately, such as in tests or synchronous API endpoints.
With User ID
Pass an optional user ID to record who triggered the workflow:
php
$instances = Workflowable::dispatch($event, userId: auth()->id());The user ID is stored as created_by on the WorkflowInstance.
Checking Results
php
foreach ($instances as $instance) {
$instance->status; // 'completed', 'pending', 'in_progress', 'failed'
$instance->current_step; // null when completed, or the step name
$instance->getVariable('receipt_id'); // Access workflow data
}Finding Instances Later
php
use Workflowable\Workflowable\Models\WorkflowInstance;
$instance = WorkflowInstance::findOrFail($instanceId);Queue Configuration
Async dispatch uses the queue settings from config/workflowable.php:
php
'execution' => [
'queue' => 'default', // Queue name
'connection' => null, // Queue connection (null = app default)
],