diff --git a/src/Tenant.php b/src/Tenant.php index 2f6d8ae2..87aff8da 100644 --- a/src/Tenant.php +++ b/src/Tenant.php @@ -59,12 +59,15 @@ class Tenant implements ArrayAccess public static function fromStorage(array $data): self { - return static::new()->withData($data)->persisted(); + return static::new()->withData($data)->persisted(true); } - protected function persisted() + protected function persisted($persisted = null) { - $this->persisted = true; + if (gettype($persisted) === 'bool') { + $this->persisted = $persisted; + return $this; + } return $this; } @@ -108,6 +111,35 @@ class Tenant implements ArrayAccess return $this; } + /** + * Delete a tenant from storage. + * + * @return self + */ + public function delete(): self + { + if ($this->persisted) { + $this->tenantManager->deleteTenant($this); + $this->persisted = false; + } + + return $this; + } + + /** + * Unassign all domains from the tenant. + * + * @return self + */ + public function softDelete(): self + { + $this->put('_tenancy_original_domains', $this->domains); + $this->domains = []; + $this->save(); + + return $this; + } + public function getDatabaseName() { return $this['_tenancy_db_name'] ?? $this->app['config']['tenancy.database.prefix'] . $this->uuid . $this->app['config']['tenancy.database.suffix'];