Skip to content

Commit

Permalink
Add tenant singleton
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebronner committed Oct 11, 2019
1 parent 8f203a5 commit c5db0bc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/Providers/Tool.php
Expand Up @@ -5,6 +5,9 @@
use GeneaLabs\NovaMultiTenantManager\Console\Commands\DeleteTenant;
use GeneaLabs\NovaMultiTenantManager\Console\Commands\Publish;
use GeneaLabs\NovaMultiTenantManager\Http\Middleware\Authorize;
use GeneaLabs\NovaMultiTenantManager\Tenant;
use Hyn\Tenancy\Environment;
use Hyn\Tenancy\Models\Website;
use Illuminate\Support\Facades\Route;
use Illuminate\Support\ServiceProvider;

Expand All @@ -21,6 +24,21 @@ public function boot()
__DIR__ . '/../../config/nova-multi-tenant-manager.php' => config_path('nova-multi-tenant-manager.php')
], 'config');

$this->app->singleton("tenant", function () {
$website = app(Environment::class)->tenant();

if (! $website) {
$websiteUuid = config('database.connections.tenant.uuid');
$website = (new Website)->where("uuid", $websiteUuid)->first();
$environment = app(Environment::class);
$environment->tenant($website);
}

return (new Tenant)
->where("website_id", $website->id)
->first();
});

$this->app->booted(function () {
$this->routes();
});
Expand Down

0 comments on commit c5db0bc

Please sign in to comment.