mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 17:54:03 +00:00
Use database transactions for creating users & granting permissions
This commit is contained in:
parent
70e6679678
commit
65ebc043dc
12 changed files with 66 additions and 48 deletions
26
src/Traits/CreatesDatabaseUsers.php
Normal file
26
src/Traits/CreatesDatabaseUsers.php
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Traits;
|
||||
|
||||
use Stancl\Tenancy\Tenant;
|
||||
|
||||
trait CreatesDatabaseUsers
|
||||
{
|
||||
public function createDatabase(Tenant $tenant): bool
|
||||
{
|
||||
return $this->database()->transaction(function () use ($tenant) {
|
||||
parent::createDatabase($tenant);
|
||||
|
||||
return $this->createUser($tenant->database());
|
||||
});
|
||||
}
|
||||
|
||||
public function deleteDatabase(Tenant $tenant): bool
|
||||
{
|
||||
return $this->database()->transaction(function () use ($tenant) {
|
||||
parent::deleteDatabase($tenant);
|
||||
|
||||
return $this->deleteUser($tenant->database());
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue