From b874a45724e33052348971a73f1b120df04d7454 Mon Sep 17 00:00:00 2001 From: ncoronel Date: Thu, 25 Jun 2026 12:07:52 -0300 Subject: [PATCH] feat(attachments): create Attachment model and migration for file attachments --- app/Domains/Attachable/Models/Attachment.php | 43 +++++++++++++++++++ app/Domains/Tenant/Models/Tenant.php | 1 - ..._06_25_000500_create_attachments_table.php | 40 +++++++++++++++++ 3 files changed, 83 insertions(+), 1 deletion(-) create mode 100644 app/Domains/Attachable/Models/Attachment.php create mode 100644 database/migrations/2026_06_25_000500_create_attachments_table.php diff --git a/app/Domains/Attachable/Models/Attachment.php b/app/Domains/Attachable/Models/Attachment.php new file mode 100644 index 0000000..5eef51b --- /dev/null +++ b/app/Domains/Attachable/Models/Attachment.php @@ -0,0 +1,43 @@ + 'integer', + 'is_public' => 'boolean', + 'size' => 'integer', + ]; + } + + /** + * @return MorphTo + */ + public function attachable(): MorphTo + { + return $this->morphTo(); + } +} diff --git a/app/Domains/Tenant/Models/Tenant.php b/app/Domains/Tenant/Models/Tenant.php index a016a30..0139ab2 100644 --- a/app/Domains/Tenant/Models/Tenant.php +++ b/app/Domains/Tenant/Models/Tenant.php @@ -47,7 +47,6 @@ class Tenant extends Model { return $this->hasMany(Product::class, 'tenant_codigo', 'codigo'); } - /** * @return HasMany */ diff --git a/database/migrations/2026_06_25_000500_create_attachments_table.php b/database/migrations/2026_06_25_000500_create_attachments_table.php new file mode 100644 index 0000000..c5a0431 --- /dev/null +++ b/database/migrations/2026_06_25_000500_create_attachments_table.php @@ -0,0 +1,40 @@ +id(); + $table->string('attachable_type'); + $table->unsignedBigInteger('attachable_id'); + $table->string('path'); + $table->string('filename'); + $table->string('type')->nullable(); + $table->string('mime_type'); + $table->boolean('is_public')->default(false); + $table->string('extension', 20)->nullable(); + $table->unsignedBigInteger('size')->default(0); + $table->timestamps(); + + $table->index(['attachable_type', 'attachable_id']); + $table->index('type'); + $table->index('mime_type'); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('attachments'); + } +};