feat(attachments): ensure 'key' is set as UUID on attachment creation and update tests for key validation

This commit is contained in:
2026-06-25 15:11:31 -03:00
parent aec92d5346
commit ee59236d55
3 changed files with 16 additions and 5 deletions

View File

@@ -12,6 +12,7 @@ use Illuminate\Support\Str;
#[Fillable([
'attachable_type',
'attachable_id',
'key',
'path',
'filename',
'type',
@@ -28,7 +29,9 @@ class Attachment extends Model
protected static function booted(): void
{
static::creating(function (self $attachment): void {
$attachment->key = (string) Str::uuid();
if (! $attachment->key) {
$attachment->key = (string) Str::uuid();
}
});
}