-
-
Notifications
You must be signed in to change notification settings - Fork 154
/
Copy pathMultitenancyServiceProvider.php
41 lines (33 loc) · 1.35 KB
/
MultitenancyServiceProvider.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Spatie\Multitenancy;
use Illuminate\Support\Facades\Event;
use Laravel\Octane\Events\RequestReceived as OctaneRequestReceived;
use Laravel\Octane\Events\RequestTerminated as OctaneRequestTerminated;
use Spatie\LaravelPackageTools\Package;
use Spatie\LaravelPackageTools\PackageServiceProvider;
use Spatie\Multitenancy\Commands\TenantsArtisanCommand;
use Spatie\Multitenancy\Concerns\UsesMultitenancyConfig;
use Spatie\Multitenancy\Models\Concerns\UsesTenantModel;
class MultitenancyServiceProvider extends PackageServiceProvider
{
use UsesTenantModel;
use UsesMultitenancyConfig;
public function configurePackage(Package $package): void
{
$package
->name('laravel-multitenancy')
->hasConfigFile()
->hasMigration('landlord/create_landlord_tenants_table')
->hasCommand(TenantsArtisanCommand::class);
}
public function packageBooted(): void
{
$this->app->bind(Multitenancy::class, fn ($app) => new Multitenancy($app));
if (! isset($_SERVER['LARAVEL_OCTANE'])) {
app(Multitenancy::class)->start();
return;
}
Event::listen(fn (OctaneRequestReceived $requestReceived) => app(Multitenancy::class)->start());
Event::listen(fn (OctaneRequestTerminated $requestTerminated) => app(Multitenancy::class)->end());
}
}