homeos/app/Models/Concerns/HasUuid.php

26 lines
469 B
PHP

<?php
namespace App\Models\Concerns;
use Illuminate\Support\Str;
/**
* Integer PK + a stable `uuid` used as the public route key (R11).
*/
trait HasUuid
{
protected static function bootHasUuid(): void
{
static::creating(function ($model) {
if (empty($model->uuid)) {
$model->uuid = (string) Str::uuid();
}
});
}
public function getRouteKeyName(): string
{
return 'uuid';
}
}