Skip to content

Commit 65beecf

Browse files
committed
BroadcastingConfigBootstrapper: clear the Broadcast facade's resolved Broadcasting\Factory instance
After initializing tenancy, calls like `Broadcast::auth()` use the central `BroadcastManager`. Clearing the facade's resolved `Broadcasting\Factory` instance fixes that problem.
1 parent b1e91f1 commit 65beecf

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/Bootstrappers/BroadcastingConfigBootstrapper.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Stancl\Tenancy\Contracts\TenancyBootstrapper;
1212
use Stancl\Tenancy\Contracts\Tenant;
1313
use Stancl\Tenancy\Overrides\TenancyBroadcastManager;
14+
use Illuminate\Support\Facades\Broadcast;
15+
use Illuminate\Contracts\Broadcasting\Factory as BroadcastingFactory;
1416

1517
class BroadcastingConfigBootstrapper implements TenancyBootstrapper
1618
{
@@ -81,6 +83,10 @@ public function bootstrap(Tenant $tenant): void
8183
$this->app->extend(Broadcaster::class, function (Broadcaster $broadcaster) {
8284
return $this->app->make(BroadcastManager::class)->connection();
8385
});
86+
87+
// Clear the resolved Broadcast facade instance so that it gets re-resolved as the tenant broadcast manager
88+
// when used (e.g. in BroadcastController::authenticate)
89+
Broadcast::clearResolvedInstance(BroadcastingFactory::class);
8490
}
8591

8692
public function revert(): void
@@ -89,6 +95,9 @@ public function revert(): void
8995
$this->app->singleton(BroadcastManager::class, fn (Application $app) => $this->originalBroadcastManager);
9096
$this->app->singleton(Broadcaster::class, fn (Application $app) => $this->originalBroadcaster);
9197

98+
// Clear the resolved Broadcast facade instance so that it gets re-resolved as the central broadcast manager
99+
Broadcast::clearResolvedInstance(BroadcastingFactory::class);
100+
92101
$this->unsetConfig();
93102
}
94103

0 commit comments

Comments
 (0)