1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2025-12-15 18:34:03 +00:00
tenancy/src/Database/Concerns/GeneratesIds.php
2020-05-30 15:38:29 +02:00

29 lines
706 B
PHP

<?php
declare(strict_types=1);
namespace Stancl\Tenancy\Database\Concerns;
use Stancl\Tenancy\Contracts\UniqueIdentifierGenerator;
trait GeneratesIds
{
public static function bootGeneratesIds()
{
static::creating(function (self $model) {
if (! $model->getTenantKey() && $model->shouldGenerateId()) {
$model->setAttribute($model->getTenantKeyName(), app(UniqueIdentifierGenerator::class)->generate($model));
}
});
}
public function getIncrementing()
{
return ! app()->bound(UniqueIdentifierGenerator::class);
}
public function shouldGenerateId(): bool
{
return ! $this->getIncrementing();
}
}