mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-15 08:24:05 +00:00
Refactor models & config
This commit is contained in:
parent
f0ff8248e7
commit
2839f45196
9 changed files with 123 additions and 97 deletions
19
src/Database/Concerns/EnsuresDomainIsNotOccupied.php
Normal file
19
src/Database/Concerns/EnsuresDomainIsNotOccupied.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
namespace Stancl\Tenancy\Database\Concerns;
|
||||
|
||||
use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException;
|
||||
|
||||
trait EnsuresDomainIsNotOccupied
|
||||
{
|
||||
public static function bootEnsuresDomainIsNotOccupied()
|
||||
{
|
||||
static::saving(function ($self) {
|
||||
if ($domain = $self->newQuery()->where('domain', $self->domain)->first()) {
|
||||
if ($domain->getKey() !== $self->getKey()) {
|
||||
throw new DomainOccupiedByOtherTenantException($self->domain);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue