Files
Website/app/Traits/Uuids.php
2023-05-24 21:33:17 +00:00

37 lines
696 B
PHP

<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait Uuids
{
/**
* Boot function from Laravel.
*/
protected static function bootUuids(): void
{
static::creating(function ($model) {
if (empty($model->{$model->getKeyName()}) === true) {
$model->{$model->getKeyName()} = Str::uuid()->toString();
}
});
}
/**
* Get the value indicating whether the IDs are incrementing.
*/
public function getIncrementing(): bool
{
return false;
}
/**
* Get the auto-incrementing key type.
*/
public function getKeyType(): string
{
return 'string';
}
}