@@ -23,16 +23,20 @@ public function packageBooted()
2323 {
2424 Route::macro ('webhooks ' , function (string $ url , string $ name = 'default ' , $ method = 'post ' ) {
2525
26- if (! in_array ($ method , ['get ' , 'post ' , 'put ' , 'patch ' , 'delete ' ])) {
26+ if (! in_array ($ method , ['get ' , 'post ' , 'put ' , 'patch ' , 'delete ' ])) {
2727 throw InvalidMethod::make ($ method );
2828 }
2929
30+ if (config ('webhook-client.add_unique_token_to_route_name ' , false )) {
31+ $ name .= '. ' . Str::random (8 );
32+ }
33+
3034 return Route::{$ method }($ url , '\Spatie\WebhookClient\Http\Controllers\WebhookController ' )
31- ->name ("webhook-client- {$ name }. " . Str:: random ( 8 ) );
35+ ->name ("webhook-client- {$ name }" );
3236 });
3337
3438 $ this ->app ->scoped (WebhookConfigRepository::class, function () {
35- $ configRepository = new WebhookConfigRepository () ;
39+ $ configRepository = new WebhookConfigRepository ;
3640
3741 collect (config ('webhook-client.configs ' ))
3842 ->map (fn (array $ config ) => new WebhookConfig ($ config ))
@@ -44,9 +48,13 @@ public function packageBooted()
4448 $ this ->app ->bind (WebhookConfig::class, function () {
4549 $ routeName = Route::currentRouteName () ?? '' ;
4650
47- $ routeNameSuffix = Str::after ($ routeName , 'webhook-client- ' );
51+ $ configName = Str::after ($ routeName , 'webhook-client- ' );
4852
49- $ configName = Str::before ($ routeNameSuffix , '. ' );
53+ if (config ('webhook-client.add_unique_token_to_route_name ' , false )) {
54+ $ routeNameSuffix = Str::after ($ routeName , 'webhook-client- ' );
55+
56+ $ configName = Str::before ($ routeNameSuffix , '. ' );
57+ }
5058
5159 $ webhookConfig = app (WebhookConfigRepository::class)->getConfig ($ configName );
5260
0 commit comments