feat(attachments): refactor attachment management to use attachable pivot table and update related models and tests
This commit is contained in:
@@ -6,12 +6,10 @@ 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\MorphTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Fillable([
|
||||
'attachable_type',
|
||||
'attachable_id',
|
||||
'key',
|
||||
'path',
|
||||
'filename',
|
||||
@@ -38,17 +36,16 @@ class Attachment extends Model
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'attachable_id' => 'integer',
|
||||
'type' => AttachmentType::class,
|
||||
'size' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return MorphTo<Model, $this>
|
||||
* @return HasMany<AttachableAttachment, $this>
|
||||
*/
|
||||
public function attachable(): MorphTo
|
||||
public function attachables(): HasMany
|
||||
{
|
||||
return $this->morphTo();
|
||||
return $this->hasMany(AttachableAttachment::class, 'attachment_id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user