spatie / laravel-webhook-client

Receive webhooks in Laravel apps
https://freek.dev/1383-sending-and-receiving-webhooks-in-laravel-apps
MIT License
985 stars 146 forks source link

multiple config array indices #189

Closed macbookandrew closed 1 year ago

macbookandrew commented 1 year ago

This assists apps using multiple webhook configs by allowing arbitrary index keys to be used

Specific use case: when testing one of multiple endpoints in my app, I need to set a config value:

/**
 * Before
 */

// Find the key:
$key = collect(config('webhook-client.configs'))->where('name', 'new-issues')->keys()->first();
config(['webhook-client.configs.'.$key.'.signing_secret' => 'secret']);

// Or loop through them all:
collect(config('webhook-client.configs'))
  ->each(function (array $config, int $index) {
    if ($config['name'] === 'new-issues') {
      config(['webhook-client.configs.'.$index.'.signing_secret' => 'secret']);
    }
  });

// Or this, which breaks if the config file is reordered:
config(['webhook-client.configs.2.signing_secret' => 'secret']);

/**
 * After
 */
config(['webhook-client.configs.new-issues.signing_secret' => 'secret']);

Another specific use case: in some of my endpoints, I use other config values in the webhook profile class and want to retrieve those from the config:

/**
 * Before
 */
$formIds = collect(config('webhook-client.configs'))->firstWhere('name', 'new-issues')['form-ids'];

/**
 * After
 */
$formIds = config('webhook-client.configs.new-issues.form-ids');

I realize that I can add my own array indices in my app and that does work fine. I figured this may be useful to a wider audience as well, and added the ability to use the index key as the name.

This should be backwards-compatible for existing installations.

spatie-bot commented 1 year ago

Dear contributor,

because this pull request seems to be inactive for quite some time now, I've automatically closed it. If you feel this pull request deserves some attention from my human colleagues feel free to reopen it.

macbookandrew commented 1 year ago

@freekmurze what do you think?