mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 21:54:03 +00:00
DB transactions
This commit is contained in:
parent
a5a9f47eaa
commit
46609c5b0d
2 changed files with 27 additions and 20 deletions
|
|
@ -90,6 +90,7 @@ class DatabaseStorageDriver implements StorageDriver
|
|||
|
||||
public function updateTenant(Tenant $tenant): void
|
||||
{
|
||||
DB::transaction(function () use ($tenant) {
|
||||
Tenants::find($tenant->id)->putMany($tenant->data);
|
||||
|
||||
$original_domains = Domains::where('tenant_id', $tenant->id)->get()->map(function ($model) {
|
||||
|
|
@ -105,12 +106,15 @@ class DatabaseStorageDriver implements StorageDriver
|
|||
'domain' => $domain,
|
||||
]);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteTenant(Tenant $tenant): void
|
||||
{
|
||||
DB::transacton(function () use ($tenant) {
|
||||
Tenants::find($tenant->id)->delete();
|
||||
Domains::where('tenant_id', $tenant->id)->delete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -111,17 +111,20 @@ class Tenant implements ArrayAccess
|
|||
return static::new()->withDomains((array) $domains)->withData($data)->save();
|
||||
}
|
||||
|
||||
protected function persisted($persisted = null)
|
||||
/**
|
||||
* DO NOT CALL THIS METHOD FROM USERLAND UNLESS YOU KNOW WHAT YOU ARE DOING.
|
||||
* Set $persisted.
|
||||
*
|
||||
* @param bool $persisted
|
||||
* @return self
|
||||
*/
|
||||
public function persisted(bool $persisted): self
|
||||
{
|
||||
if (gettype($persisted) === 'boolean') {
|
||||
$this->persisted = $persisted;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this model exist in the tenant storage.
|
||||
*
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue