mirror of
https://github.com/archtechx/tenancy.git
synced 2025-12-12 11:14:04 +00:00
21 lines
574 B
PHP
21 lines
574 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
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);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
}
|