Overview
TheWorkflowStub class is your primary interface for interacting with workflows. It provides methods to:
- Create new workflow instances
- Load existing workflows
- Start workflow execution
- Send signals to running workflows
- Query workflow state
- Check workflow status
WorkflowStub as the “handle” you use to control and communicate with workflows.
Creating Workflows
UseWorkflowStub::make() to create a new workflow instance:
StoredWorkflow record in the database with a created status:
src/WorkflowStub.php
Loading Existing Workflows
Load a workflow by its ID usingWorkflowStub::load():
StoredWorkflow model:
src/WorkflowStub.php
Starting Workflows
Once you’ve created a workflow, start it withstart():
start() method:
- Serializes the arguments
- Transitions the workflow to “pending” status
- Dispatches the workflow job to the queue
src/WorkflowStub.php
Getting Workflow Information
Workflow ID
Get the unique workflow identifier:Workflow Status
Check the current status of a workflow:src/WorkflowStub.php
Workflow Output
Retrieve the return value from a completed workflow:src/WorkflowStub.php
Workflow Logs
Access execution logs for debugging:Workflow Exceptions
Retrieve exceptions that occurred during execution:Refreshing Workflow State
Reload the workflow’s state from the database:src/WorkflowStub.php
Signaling Workflows
Send signals to running workflows using the magic__call method:
src/WorkflowStub.php
Querying Workflows
Query methods let you read workflow state without modifying it:src/WorkflowStub.php
Update Methods
Update methods combine query and signal behavior—they return a value immediately and can modify state:src/WorkflowStub.php
Resuming Workflows
Manually resume a waiting workflow:src/WorkflowStub.php
Child Workflows
Start a workflow as a child of another workflow:src/WorkflowStub.php
Workflow Context
Access execution context from within a workflow:src/WorkflowStub.php
Method Detection
WorkflowStub caches method type detection for performance:src/WorkflowStub.php
isQueryMethod and isUpdateMethod.
Best Practices
Always check status before querying output
Only call
output() on completed workflows to avoid getting null values.Use signals for external events
When external systems need to notify a workflow, use signal methods.
Use queries for read-only access
Query methods are safe and don’t modify workflow state.
Refresh before checking status
Call
fresh() before checking status if the workflow may have changed.Next Steps
State Management
Learn about workflow states and transitions
Durability
Understand how workflows persist and replay