mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 16:14:03 +00:00
use Laravel's connection getter and setter
This commit is contained in:
parent
0e72c71286
commit
cc2df5c0b6
1 changed files with 5 additions and 20 deletions
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue