mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:54: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);
|
$batchRepository = app(BatchRepository::class);
|
||||||
|
|
||||||
if ($batchRepository instanceof DatabaseBatchRepository) {
|
if ($batchRepository instanceof DatabaseBatchRepository) {
|
||||||
/**
|
// Access the resolved batch repository instance and update its connection to use the tenant connection
|
||||||
* Access the resolved batch repository instance and update its connection to use the tenant connection
|
$this->previousConnection = $batchRepository->getConnection();
|
||||||
*/
|
$batchRepository->setConnection(DB::connection('tenant'));
|
||||||
$batchRepositoryReflection = new ReflectionClass($batchRepository);
|
|
||||||
$connectionProperty = $batchRepositoryReflection->getProperty('connection');
|
|
||||||
$connectionProperty->setAccessible(true);
|
|
||||||
$connection = $connectionProperty->getValue($batchRepository);
|
|
||||||
|
|
||||||
$this->previousConnection = $connection;
|
|
||||||
|
|
||||||
$connectionProperty->setValue($batchRepository, 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
|
||||||
* Access the resolved batch repository instance and replace its connection with the previously replaced one
|
|
||||||
*/
|
|
||||||
$batchRepository = app(BatchRepository::class);
|
$batchRepository = app(BatchRepository::class);
|
||||||
|
$batchRepository->setConnection($this->previousConnection);
|
||||||
$batchRepositoryReflection = new ReflectionClass($batchRepository);
|
|
||||||
$connectionProperty = $batchRepositoryReflection->getProperty('connection');
|
|
||||||
$connectionProperty->setAccessible(true);
|
|
||||||
|
|
||||||
$connectionProperty->setValue($batchRepository, $this->previousConnection);
|
|
||||||
$this->previousConnection = null;
|
$this->previousConnection = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue