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

use tenant connection and central connection listener

This commit is contained in:
Abrar Ahmad 2022-11-23 14:45:55 +05:00
parent 03d9dd6813
commit 27c05f28cc
2 changed files with 45 additions and 0 deletions

View 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'));
}
}

View 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');
}
}