mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:14:04 +00:00
use tenant connection and central connection listener
This commit is contained in:
parent
03d9dd6813
commit
27c05f28cc
2 changed files with 45 additions and 0 deletions
24
src/Listeners/UseCentralConnection.php
Normal file
24
src/Listeners/UseCentralConnection.php
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Listeners;
|
||||||
|
|
||||||
|
use Illuminate\Foundation\Application;
|
||||||
|
use Stancl\Tenancy\Database\DatabaseManager;
|
||||||
|
use Stancl\Tenancy\Events\Contracts\TenancyEvent;
|
||||||
|
|
||||||
|
class UseCentralConnection
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected DatabaseManager $database,
|
||||||
|
protected Application $app
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(TenancyEvent $event): void
|
||||||
|
{
|
||||||
|
$this->database->purgeTenantConnection();
|
||||||
|
$this->database->setDefaultConnection($this->app['config']->get('tenancy.database.central_connection'));
|
||||||
|
}
|
||||||
|
}
|
||||||
21
src/Listeners/UseTenantConnection.php
Normal file
21
src/Listeners/UseTenantConnection.php
Normal file
|
|
@ -0,0 +1,21 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace Stancl\Tenancy\Listeners;
|
||||||
|
|
||||||
|
use Stancl\Tenancy\Database\DatabaseManager;
|
||||||
|
use Stancl\Tenancy\Events\Contracts\TenancyEvent;
|
||||||
|
|
||||||
|
class UseTenantConnection
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
protected DatabaseManager $database,
|
||||||
|
) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public function handle(TenancyEvent $event): void
|
||||||
|
{
|
||||||
|
$this->database->setDefaultConnection('tenant');
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue