feat(attachments): add 'key' field to Attachment model and migration, generate UUID on creation
This commit is contained in:
@@ -6,6 +6,7 @@ use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphTo;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Fillable([
|
||||
'attachable_type',
|
||||
@@ -23,6 +24,13 @@ class Attachment extends Model
|
||||
|
||||
protected $table = 'attachments';
|
||||
|
||||
protected static function booted(): void
|
||||
{
|
||||
static::creating(function (self $attachment): void {
|
||||
$attachment->key = (string) Str::uuid();
|
||||
});
|
||||
}
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
|
||||
Reference in New Issue
Block a user