28 lines
459 B
PHP
28 lines
459 B
PHP
<?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';
|
|
}
|
|
}
|