mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 18:04:03 +00:00
delete() method on Tenant
This commit is contained in:
parent
8bb13c7159
commit
2657df5a88
1 changed files with 35 additions and 3 deletions
|
|
@ -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'];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue