diff --git a/src/Bootstrappers/BatchTenancyBootstrapper.php b/src/Bootstrappers/BatchTenancyBootstrapper.php index 515a4f06..e81617ab 100644 --- a/src/Bootstrappers/BatchTenancyBootstrapper.php +++ b/src/Bootstrappers/BatchTenancyBootstrapper.php @@ -23,33 +23,18 @@ class BatchTenancyBootstrapper implements TenancyBootstrapper $batchRepository = app(BatchRepository::class); if ($batchRepository instanceof DatabaseBatchRepository) { - /** - * Access the resolved batch repository instance and update its connection to use the tenant connection - */ - $batchRepositoryReflection = new ReflectionClass($batchRepository); - $connectionProperty = $batchRepositoryReflection->getProperty('connection'); - $connectionProperty->setAccessible(true); - $connection = $connectionProperty->getValue($batchRepository); - - $this->previousConnection = $connection; - - $connectionProperty->setValue($batchRepository, DB::connection('tenant')); + // Access the resolved batch repository instance and update its connection to use the tenant connection + $this->previousConnection = $batchRepository->getConnection(); + $batchRepository->setConnection(DB::connection('tenant')); } } public function revert() { if ($this->previousConnection) { - /** - * Access the resolved batch repository instance and replace its connection with the previously replaced one - */ + // Access the resolved batch repository instance and replace its connection with the previously replaced one $batchRepository = app(BatchRepository::class); - - $batchRepositoryReflection = new ReflectionClass($batchRepository); - $connectionProperty = $batchRepositoryReflection->getProperty('connection'); - $connectionProperty->setAccessible(true); - - $connectionProperty->setValue($batchRepository, $this->previousConnection); + $batchRepository->setConnection($this->previousConnection); $this->previousConnection = null; } }