Files
Website/app.old/Traits/Uuids.php
2023-11-27 08:29:48 +10:00

43 lines
782 B
PHP

<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait Uuids
{
/**
* Boot function from Laravel.
*
* @return void
*/
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.
*
* @return boolean
*/
public function getIncrementing(): bool
{
return false;
}
/**
* Get the auto-incrementing key type.
*
* @return string
*/
public function getKeyType(): string
{
return 'string';
}
}