1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 19:14:04 +00:00

delete() method on Tenant

This commit is contained in:
Samuel Štancl 2019-09-15 09:35:06 +02:00
parent 8bb13c7159
commit 2657df5a88

View file

@ -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'];