22 lines
395 B
PHP
22 lines
395 B
PHP
<?php
|
|
|
|
namespace App\Models\Traits;
|
|
|
|
use Illuminate\Support\Str;
|
|
|
|
trait HasUuid
|
|
{
|
|
public static function bootHasUuid(): void
|
|
{
|
|
static::creating(function ($model) {
|
|
if (empty($model->uuid)) {
|
|
$model->uuid = (string) Str::orderedUuid();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'uuid';
|
|
}
|
|
}
|