Point the mailbox model at the UUID trait the repo already has

Seventeen models use App\Models\Concerns\HasUuid, and R11 is the reason:
URLs address records by UUID, not by integer primary key. The plan told
the implementer to hand-roll booted() instead, losing getRouteKeyName()
with it. Authoring error, corrected before the remaining tasks copy it.
feat/mailboxes
nexxo 2026-07-27 21:28:23 +02:00
parent 270ec942d6
commit c642090d97
1 changed files with 5 additions and 9 deletions

View File

@ -359,10 +359,10 @@ return new class extends Migration
namespace App\Models;
use App\Models\Concerns\HasUuid;
use App\Services\Secrets\SecretCipher;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
/**
* One sending address.
@ -373,7 +373,10 @@ use Illuminate\Support\Str;
*/
class Mailbox extends Model
{
use HasFactory;
// HasUuid assigns the uuid on create AND makes it the route key — R11:
// URLs address records by UUID, not by integer primary key. Seventeen
// models already use it; do not hand-roll a booted() replacement.
use HasFactory, HasUuid;
protected $fillable = [
'key', 'address', 'display_name', 'username',
@ -389,13 +392,6 @@ class Mailbox extends Model
];
}
protected static function booted(): void
{
static::creating(function (self $box) {
$box->uuid ??= (string) Str::uuid();
});
}
public static function findByKey(string $key): ?self
{
return static::query()->where('key', $key)->first();