From 8211ddb38a9c0a8e15634108cde676f8533a1fbc Mon Sep 17 00:00:00 2001 From: Abrar Ahmad Date: Tue, 13 Sep 2022 11:24:59 +0500 Subject: [PATCH] convert batch class resolution to property level --- .../BatchTenancyBootstrapper.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Bootstrappers/BatchTenancyBootstrapper.php b/src/Bootstrappers/BatchTenancyBootstrapper.php index bc378f36..ce891955 100644 --- a/src/Bootstrappers/BatchTenancyBootstrapper.php +++ b/src/Bootstrappers/BatchTenancyBootstrapper.php @@ -19,23 +19,24 @@ class BatchTenancyBootstrapper implements TenancyBootstrapper */ protected $previousConnection = null; + public function __construct(protected BatchRepository $batchRepository) + { + } + public function bootstrap(Tenant $tenant) { - $batchRepository = app(BatchRepository::class); - - if ($batchRepository instanceof DatabaseBatchRepository) { - // Access the resolved batch repository instance and update its connection to use the tenant connection - $this->previousConnection = $batchRepository->getConnection(); - $batchRepository->setConnection(DB::connection('tenant')); + if ($this->batchRepository instanceof DatabaseBatchRepository) { + // Update batch repository connection to use the tenant connection + $this->previousConnection = $this->batchRepository->getConnection(); + $this->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 - $batchRepository = app(BatchRepository::class); - $batchRepository->setConnection($this->previousConnection); + // Replace batch repository connection with the previously replaced one + $this->batchRepository->setConnection($this->previousConnection); $this->previousConnection = null; } }