Overview
TheWebhook attribute automatically exposes workflow methods as HTTP endpoints. It can be applied to workflow classes (to expose the execute method) or individual signal methods (to create signal endpoints).
Basic Usage
Class-Level Webhook
ApplyWebhook to the workflow class to create a start endpoint:
/webhooks/start/order-workflow that accepts POST requests:
Method-Level Webhook
ApplyWebhook to signal methods to create signal endpoints:
/webhooks/signal/order-workflow/{workflowId}/cancel:
How It Works
TheWebhooks class automatically registers routes during application boot:
- Discovery - Scans the workflows folder for all workflow classes (Webhooks.php:32-46)
- Class detection - Checks for
Webhookattribute on classes (Webhooks.php:74-76) - Method detection - Checks for
Webhookattribute on signal methods (Webhooks.php:96, 132-134) - Route registration - Creates POST routes with automatic parameter binding (Webhooks.php:70-91, 93-117)
Route Registration Code
Enabling Webhooks
Add the route registration to yourRouteServiceProvider or routes/web.php:
Parameter Binding
Webhook routes automatically bind request parameters to method arguments by name:Authentication
Webhooks support multiple authentication methods configured inconfig/workflows.php:
No Authentication
Token Authentication
Signature Authentication
Custom Authentication
WebhookAuthenticator interface:
Route Configuration
Customize the webhook base path inconfig/workflows.php:
/webhooks/start/{workflow-slug}/webhooks/signal/{workflow-slug}/{workflowId}/{signal-name}
Route Names
Routes are automatically named for use with Laravel’sroute() helper:
Combining Class and Method Webhooks
You can use both on the same workflow:POST /webhooks/start/order-workflow- Start workflowPOST /webhooks/signal/order-workflow/{id}/cancel- Cancel orderPOST /webhooks/signal/order-workflow/{id}/ship- Ship order
Response Format
Webhook endpoints return JSON responses:Attribute Target
Webhook is the only attribute that can be applied to both classes AND methods:
When to Use Webhook
UseWebhook when you need to:
- External integrations - Receive events from third-party services (Stripe, GitHub, etc.)
- API endpoints - Expose workflow operations via REST API
- Mobile apps - Allow mobile clients to trigger workflows
- Microservices - Enable other services to start or signal workflows
- Scheduled jobs - Trigger workflows from external schedulers
Discovery Process
TheWebhooks::routes() method:
- Scans the workflows directory recursively (Webhooks.php:48-59)
- Finds all PHP files (Webhooks.php:54)
- Converts file paths to class names (Webhooks.php:62-68)
- Filters for Workflow subclasses (Webhooks.php:40-43)
- Checks for
Webhookattribute on classes and methods (Webhooks.php:74-76, 96) - Registers routes for each webhook-enabled method (Webhooks.php:81-88, 99-114)
Technical Details
- Target: Classes and methods (
Attribute::TARGET_CLASS | Attribute::TARGET_METHOD) - Route Method: POST only
- Parameter Binding: Automatic by name with default value support
- Authentication: Configurable per application
- Response Type: JSON
- Workflow ID: Required in URL for signal endpoints
- Slug Format: Kebab-case conversion of class name
See Also
- SignalMethod - Learn about signal methods
- WorkflowStub - Learn about starting workflows
- Authentication - Laravel authentication docs