1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-05-07 09:54:03 +00:00
tenancy/src/Database/Concerns/EnsuresDomainIsNotOccupied.php
2022-08-30 05:44:23 +02:00

21 lines
580 B
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Exceptions\DomainOccupiedByOtherTenantException;
trait EnsuresDomainIsNotOccupied
{
public static function bootEnsuresDomainIsNotOccupied(): void
{
static::saving(function ($self) {
if ($domain = $self->newQuery()->where('domain', $self->domain)->first()) {
if ($domain->getKey() !== $self->getKey()) {
throw new DomainOccupiedByOtherTenantException($self->domain);
}
}
});
}
}