Skip to content

Commit a685388

Browse files
authored
feat: register webhooks route macro in ServiceProvider::register() (#237)
1 parent fd93684 commit a685388

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/WebhookClientServiceProvider.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ public function configurePackage(Package $package): void
1919
->hasMigrations('create_webhook_calls_table');
2020
}
2121

22-
public function packageBooted()
22+
public function packageRegistered()
2323
{
2424
Route::macro('webhooks', function (string $url, string $name = 'default', $method = 'post') {
25-
2625
if (! in_array($method, ['get', 'post', 'put', 'patch', 'delete'])) {
2726
throw InvalidMethod::make($method);
2827
}
@@ -34,6 +33,19 @@ public function packageBooted()
3433
return Route::{$method}($url, '\Spatie\WebhookClient\Http\Controllers\WebhookController')
3534
->name("webhook-client-{$name}");
3635
});
36+
}
37+
38+
public function packageBooted()
39+
{
40+
$this->app->scoped(WebhookConfigRepository::class, function () {
41+
$configRepository = new WebhookConfigRepository();
42+
43+
collect(config('webhook-client.configs'))
44+
->map(fn (array $config) => new WebhookConfig($config))
45+
->each(fn (WebhookConfig $webhookConfig) => $configRepository->addConfig($webhookConfig));
46+
47+
return $configRepository;
48+
});
3749

3850
$this->app->scoped(WebhookConfigRepository::class, function () {
3951
$configRepository = new WebhookConfigRepository();

0 commit comments

Comments
 (0)