feat: implement Attachment domain for file storage and integrate into Tenant service for logo management

This commit is contained in:
2026-06-29 09:43:46 -03:00
parent 67bc9e6cb4
commit b0508d79b3
9 changed files with 2 additions and 179 deletions

View File

@@ -1,44 +0,0 @@
<?php
namespace App\Domains\Attachable\Models;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\MorphTo;
#[Fillable([
'attachable_type',
'attachable_id',
'attachment_id',
])]
class AttachableAttachment extends Model
{
protected $table = 'attachable_attachments';
public $timestamps = false;
protected function casts(): array
{
return [
'attachable_id' => 'integer',
'attachment_id' => 'integer',
];
}
/**
* @return MorphTo<Model, $this>
*/
public function attachable(): MorphTo
{
return $this->morphTo();
}
/**
* @return BelongsTo<Attachment, $this>
*/
public function attachment(): BelongsTo
{
return $this->belongsTo(Attachment::class, 'attachment_id');
}
}

View File

@@ -6,7 +6,6 @@ use App\Domains\Attachable\Enums\AttachmentType;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Support\Str;
#[Fillable([
@@ -41,14 +40,6 @@ class Attachment extends Model
];
}
/**
* @return HasMany<AttachableAttachment, $this>
*/
public function attachables(): HasMany
{
return $this->hasMany(AttachableAttachment::class, 'attachment_id');
}
/**
* Get the pre-signed temporary S3 URL for this attachment.
*/

View File

@@ -1,24 +0,0 @@
<?php
namespace App\Domains\Attachable\Models\Concerns;
use App\Domains\Attachable\Models\Attachment;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
trait HasAttachments
{
/**
* @return MorphToMany<Attachment, Model, $this>
*/
public function attachments(): MorphToMany
{
return $this->morphToMany(
Attachment::class,
'attachable',
'attachable_attachments',
'attachable_id',
'attachment_id',
);
}
}

View File

@@ -3,7 +3,6 @@
namespace App\Domains\Tenant\Models;
use App\Domains\Attachable\Models\Attachment;
use App\Domains\Attachable\Models\Concerns\HasAttachments;
use App\Domains\Catalog\Models\Product;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Factories\HasFactory;
@@ -24,7 +23,6 @@ use Illuminate\Database\Eloquent\Relations\HasMany;
])]
class Tenant extends Model
{
use HasAttachments;
use HasFactory;
public function getRouteKeyName(): string

View File

@@ -55,14 +55,6 @@ class TenantService
/** @var Tenant $tenant */
$tenant = Tenant::query()->create($data);
if ($headerAttachmentId) {
$tenant->attachments()->attach($headerAttachmentId);
}
if ($footerAttachmentId) {
$tenant->attachments()->attach($footerAttachmentId);
}
return $tenant;
});
}
@@ -94,7 +86,6 @@ class TenantService
if ($attachment) {
$tenant->header_logo_id = $attachment->id;
$tenant->attachments()->attach($attachment->id);
} else {
$tenant->header_logo_id = null;
}
@@ -111,7 +102,6 @@ class TenantService
if ($attachment) {
$tenant->footer_logo_id = $attachment->id;
$tenant->attachments()->attach($attachment->id);
} else {
$tenant->footer_logo_id = null;
}