diff --git a/src/WebhookClientServiceProvider.php b/src/WebhookClientServiceProvider.php index ad1b92d..a5aa688 100644 --- a/src/WebhookClientServiceProvider.php +++ b/src/WebhookClientServiceProvider.php @@ -27,7 +27,8 @@ public function packageBooted() throw InvalidMethod::make($method); } - return Route::{$method}($url, '\Spatie\WebhookClient\Http\Controllers\WebhookController')->name("webhook-client-{$name}"); + return Route::{$method}($url, '\Spatie\WebhookClient\Http\Controllers\WebhookController') + ->name("webhook-client-{$name}." . Str::random(8)); }); $this->app->scoped(WebhookConfigRepository::class, function () { @@ -43,7 +44,9 @@ public function packageBooted() $this->app->bind(WebhookConfig::class, function () { $routeName = Route::currentRouteName() ?? ''; - $configName = Str::after($routeName, 'webhook-client-'); + $routeNameSuffix = Str::after($routeName, 'webhook-client-'); + + $configName = Str::before($routeNameSuffix, '.'); $webhookConfig = app(WebhookConfigRepository::class)->getConfig($configName); diff --git a/tests/WebhookControllerTest.php b/tests/WebhookControllerTest.php index 1600f02..27a84e0 100644 --- a/tests/WebhookControllerTest.php +++ b/tests/WebhookControllerTest.php @@ -204,6 +204,21 @@ public function it_can_store_none_of_the_headers() $this->assertEquals(0, count(WebhookCall::first()->headers)); } + /** @test */ + public function multiple_routes_can_share_configuration() + { + Route::webhooks('incoming-webhooks-additional'); + + $this->refreshWebhookConfigRepository(); + + $routeNames = collect(Route::getRoutes()) + ->map(fn ($route) => $route->getName()); + + $uniqueRouteNames = $routeNames->unique(); + + $this->assertEquals($routeNames->count(), $uniqueRouteNames->count()); + } + protected function determineSignature(array $payload): string { $secret = config('webhook-client.configs.0.signing_secret');