1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-02-05 20:34:03 +00:00

convert batch class resolution to property level

This commit is contained in:
Abrar Ahmad 2022-09-13 11:24:59 +05:00
parent df172ffc23
commit 8211ddb38a

View file

@ -19,23 +19,24 @@ class BatchTenancyBootstrapper implements TenancyBootstrapper
*/ */
protected $previousConnection = null; protected $previousConnection = null;
public function __construct(protected BatchRepository $batchRepository)
{
}
public function bootstrap(Tenant $tenant) public function bootstrap(Tenant $tenant)
{ {
$batchRepository = app(BatchRepository::class); if ($this->batchRepository instanceof DatabaseBatchRepository) {
// Update batch repository connection to use the tenant connection
if ($batchRepository instanceof DatabaseBatchRepository) { $this->previousConnection = $this->batchRepository->getConnection();
// Access the resolved batch repository instance and update its connection to use the tenant connection $this->batchRepository->setConnection(DB::connection('tenant'));
$this->previousConnection = $batchRepository->getConnection();
$batchRepository->setConnection(DB::connection('tenant'));
} }
} }
public function revert() public function revert()
{ {
if ($this->previousConnection) { if ($this->previousConnection) {
// Access the resolved batch repository instance and replace its connection with the previously replaced one // Replace batch repository connection with the previously replaced one
$batchRepository = app(BatchRepository::class); $this->batchRepository->setConnection($this->previousConnection);
$batchRepository->setConnection($this->previousConnection);
$this->previousConnection = null; $this->previousConnection = null;
} }
} }