From aaddffc096e35b14667be4a16a2fb6d4de5ab0b3 Mon Sep 17 00:00:00 2001 From: nexxo Date: Mon, 27 Jul 2026 21:31:39 +0200 Subject: [PATCH] Reuse the existing UUID trait instead of a second copy of the logic Mailbox hand-rolled the same creating-time UUID assignment that App\Models\Concerns\HasUuid already provides to 17 other models under R11 (URLs address records by UUID, not integer PK), and skipped the route-key binding that comes with it. Swap onto the trait, and cover both the assignment and the route key with a test matching the convention already used for Host/Order. Also match MailboxFactory's @extends annotation to how the other factories in the repo write it (Pint's fully_qualified_strict_types rule turns a fully-qualified docblock reference into an import plus a short name anyway, so this is what it would end up as either way). --- app/Models/Mailbox.php | 11 ++--------- database/factories/MailboxFactory.php | 2 ++ tests/Feature/Mail/MailboxModelTest.php | 7 +++++++ 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/app/Models/Mailbox.php b/app/Models/Mailbox.php index 1950bfd..6677b80 100644 --- a/app/Models/Mailbox.php +++ b/app/Models/Mailbox.php @@ -2,10 +2,10 @@ 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. @@ -16,7 +16,7 @@ use Illuminate\Support\Str; */ class Mailbox extends Model { - use HasFactory; + use HasFactory, HasUuid; protected $fillable = [ 'key', 'address', 'display_name', 'username', @@ -32,13 +32,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(); diff --git a/database/factories/MailboxFactory.php b/database/factories/MailboxFactory.php index b5dd450..2b2cbae 100644 --- a/database/factories/MailboxFactory.php +++ b/database/factories/MailboxFactory.php @@ -2,8 +2,10 @@ namespace Database\Factories; +use App\Models\Mailbox; use Illuminate\Database\Eloquent\Factories\Factory; +/** @extends Factory */ class MailboxFactory extends Factory { public function definition(): array diff --git a/tests/Feature/Mail/MailboxModelTest.php b/tests/Feature/Mail/MailboxModelTest.php index bbf9aa5..68c8780 100644 --- a/tests/Feature/Mail/MailboxModelTest.php +++ b/tests/Feature/Mail/MailboxModelTest.php @@ -39,3 +39,10 @@ it('finds a mailbox by its key', function () { expect(Mailbox::findByKey('billing'))->not->toBeNull() ->and(Mailbox::findByKey('gibtsnicht'))->toBeNull(); }); + +it('auto-assigns a uuid and routes by it', function () { + $box = Mailbox::factory()->create(); + + expect($box->uuid)->not->toBeNull() + ->and($box->getRouteKeyName())->toBe('uuid'); +});