1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-12 11:14:04 +00:00
tenancy/src/Database/Concerns/EnsuresDomainIsNotOccupied.php
2020-05-24 18:40:24 +00:00

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);
}
}
});
}
}