Description
When Webhooks::routes() is registered in a route file with automatic prefixing (e.g., routes/api.php), the generated webhook URLs don't include the prefix, causing 404
errors.
Expected vs Actual
Routes registered at:
api/webhooks/signal/{slug}/{workflowId}/{signal}
URLs generated:
webhooks/signal/{slug}/{workflowId}/{signal}
The api/ prefix is missing from generated URLs.
Root Cause
Laravel automatically prefixes routes in routes/api.php with api/, but Activity::webhookUrl() only uses the webhooks_route config value, unaware of any route prefixes.
Attempted Workaround Fails
Setting config to 'webhooks_route' => 'api/webhooks' causes double prefixing:
api/api/webhooks/signal/...
Proposed Fix
Use Laravel's named routes and route() helper instead of manual URL construction.
Webhooks.php - Add route names:
Route::post(
"{$basePath}/signal/{$slug}/{workflowId}/{$signal}",
static function (Request $request, $workflowId) use ($workflow, $method) {
// ... handler
}
)->name("workflows.signal.{$slug}.{$signal}");
Activity.php - Use route() helper:
public function webhookUrl(string $signalMethod = ''): string
{
$workflow = Str::kebab(class_basename($this->storedWorkflow->class));
if ($signalMethod === '') {
return route("workflows.start.{$workflow}");
}
$signal = Str::kebab($signalMethod);
return route("workflows.signal.{$workflow}.{$signal}", [
'workflowId' => $this->storedWorkflow->id
]);
}
Benefits:
- Laravel's route() automatically handles all prefixes, domains, HTTPS, etc.
- Standard Laravel convention
- Works with route caching
- No manual URL construction or prefix configuration needed
Description
When
Webhooks::routes()is registered in a route file with automatic prefixing (e.g.,routes/api.php), the generated webhook URLs don't include the prefix, causing 404errors.
Expected vs Actual
Routes registered at:
api/webhooks/signal/{slug}/{workflowId}/{signal}
URLs generated:
webhooks/signal/{slug}/{workflowId}/{signal}
The
api/prefix is missing from generated URLs.Root Cause
Laravel automatically prefixes routes in
routes/api.phpwithapi/, butActivity::webhookUrl()only uses thewebhooks_routeconfig value, unaware of any route prefixes.Attempted Workaround Fails
Setting config to
'webhooks_route' => 'api/webhooks'causes double prefixing:api/api/webhooks/signal/...
Proposed Fix
Use Laravel's named routes and
route()helper instead of manual URL construction.Webhooks.php - Add route names:
Activity.php - Use route() helper:
Benefits: