mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 18:14:04 +00:00
Delete tenants on migrate:fresh
This commit is contained in:
parent
6d303d1b2e
commit
05e84401b4
1 changed files with 19 additions and 0 deletions
|
|
@ -13,6 +13,9 @@ use Stancl\Tenancy\Contracts\Tenant;
|
||||||
use Stancl\Tenancy\Enums\LogMode;
|
use Stancl\Tenancy\Enums\LogMode;
|
||||||
use Stancl\Tenancy\Events\Contracts\TenancyEvent;
|
use Stancl\Tenancy\Events\Contracts\TenancyEvent;
|
||||||
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
use Stancl\Tenancy\Resolvers\DomainTenantResolver;
|
||||||
|
use Illuminate\Console\Events\CommandStarting;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Stancl\Tenancy\Database\Contracts\TenantWithDatabase;
|
||||||
|
|
||||||
class TenancyServiceProvider extends ServiceProvider
|
class TenancyServiceProvider extends ServiceProvider
|
||||||
{
|
{
|
||||||
|
|
@ -126,6 +129,22 @@ class TenancyServiceProvider extends ServiceProvider
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Event::listen(CommandStarting::class, function (CommandStarting $event) {
|
||||||
|
$tenantModel = tenancy()->model();
|
||||||
|
|
||||||
|
if ($event->command === 'migrate:fresh' && Schema::hasTable($tenantModel->getTable())) {
|
||||||
|
$tenantModel::all()->each(function(Tenant $tenant) {
|
||||||
|
if (method_exists($tenant, 'domains')) {
|
||||||
|
$tenant->domains()->delete();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($tenant instanceof TenantWithDatabase) {
|
||||||
|
$tenant->delete();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
$this->app->singleton('globalUrl', function ($app) {
|
$this->app->singleton('globalUrl', function ($app) {
|
||||||
if ($app->bound(FilesystemTenancyBootstrapper::class)) {
|
if ($app->bound(FilesystemTenancyBootstrapper::class)) {
|
||||||
$instance = clone $app['url'];
|
$instance = clone $app['url'];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue