Aknaproff/app/Traits/UsesUuid.php

28 lines
459 B
PHP
Raw Permalink Normal View History

2023-09-21 12:45:08 +00:00
<?php
namespace App\Traits;
use Illuminate\Support\Str;
trait UsesUuid
{
protected static function bootUsesUuid()
{
static::creating(function ($model) {
if (! $model->getKey()) {
$model->{$model->getKeyName()} = (string) Str::uuid();
}
});
}
public function getIncrementing()
{
return false;
}
public function getKeyType()
{
return 'string';
}
}