From 221a9950c2f1023e36e3c9f5a1b13f223bc70999 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Mon, 13 Apr 2026 14:15:27 +0200 Subject: [PATCH] Support channel overrides using dot notation --- src/Bootstrappers/LogTenancyBootstrapper.php | 3 ++- tests/Bootstrappers/LogTenancyBootstrapperTest.php | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/Bootstrappers/LogTenancyBootstrapper.php b/src/Bootstrappers/LogTenancyBootstrapper.php index 64d0cb95..9c8812af 100644 --- a/src/Bootstrappers/LogTenancyBootstrapper.php +++ b/src/Bootstrappers/LogTenancyBootstrapper.php @@ -9,6 +9,7 @@ use Illuminate\Contracts\Config\Repository as Config; use Illuminate\Log\LogManager; use Stancl\Tenancy\Contracts\TenancyBootstrapper; use Stancl\Tenancy\Contracts\Tenant; +use Illuminate\Support\Arr; /** * This bootstrapper makes it possible to configure tenant-specific logging. @@ -128,7 +129,7 @@ class LogTenancyBootstrapper implements TenancyBootstrapper // If the tenant attribute is null, // the override is ignored and the channel config key's value remains unchanged. foreach ($override as $configKey => $tenantAttributeName) { - $tenantAttribute = $tenant->getAttribute($tenantAttributeName); + $tenantAttribute = Arr::get($tenant, $tenantAttributeName); if ($tenantAttribute !== null) { $this->config->set("logging.channels.{$channel}.{$configKey}", $tenantAttribute); diff --git a/tests/Bootstrappers/LogTenancyBootstrapperTest.php b/tests/Bootstrappers/LogTenancyBootstrapperTest.php index e83b2710..c1c2854b 100644 --- a/tests/Bootstrappers/LogTenancyBootstrapperTest.php +++ b/tests/Bootstrappers/LogTenancyBootstrapperTest.php @@ -366,11 +366,12 @@ test('slack channel uses correct webhook urls', function () { expect($thrown)->toBeTrue(); }; - $tenant1 = Tenant::create(['id' => 'tenant1', 'slackUrl' => 'tenant1-webhook']); - $tenant2 = Tenant::create(['id' => 'tenant2', 'slackUrl' => 'tenant2-webhook']); + $tenant1 = Tenant::create(['id' => 'tenant1', 'logging' => ['slackUrl' => 'tenant1-webhook']]); + $tenant2 = Tenant::create(['id' => 'tenant2', 'logging' => ['slackUrl' => 'tenant2-webhook']]); + // Attribute mapping using nested attributes (dot notation) works LogTenancyBootstrapper::$channelOverrides = [ - 'slack' => ['url' => 'slackUrl'], + 'slack' => ['url' => 'logging.slackUrl'], ]; // Test central context - should attempt to use central webhook @@ -378,7 +379,7 @@ test('slack channel uses correct webhook urls', function () { // Slack channel should attempt to use the tenant-specific webhooks tenancy()->runForMultiple([$tenant1, $tenant2], function (Tenant $tenant) use ($assertWebhook) { - $assertWebhook($tenant->slackUrl, $tenant->id); + $assertWebhook($tenant->logging['slackUrl'], $tenant->id); }); // Central context, central webhook should be used again