Refactor attachment cropping functionality to support multiple variants
- Introduced AttachmentCrop model to manage crop variants for attachments. - Updated Attachment model to remove direct crop fields and establish relationships with AttachmentCrop. - Modified AttachmentService to handle storing and updating multiple crop variants (desktop and mobile). - Adjusted validation rules to accommodate new crop structure. - Updated database migration to create attachment_crops table and migrate existing crop data. - Refactored tests to ensure compatibility with the new cropping structure and validate multiple crop variants. - Enhanced documentation to reflect changes in attachment handling and cropping capabilities.
This commit is contained in:
43
app/Domains/Attachable/Models/AttachmentCrop.php
Normal file
43
app/Domains/Attachable/Models/AttachmentCrop.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domains\Attachable\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
#[Fillable([
|
||||
'attachment_id',
|
||||
'variant',
|
||||
'crop_horizontal',
|
||||
'crop_vertical',
|
||||
'cropped_attachment_id',
|
||||
])]
|
||||
class AttachmentCrop extends Model
|
||||
{
|
||||
public const DESKTOP = 'desktop';
|
||||
|
||||
public const MOBILE = 'mobile';
|
||||
|
||||
public const VARIANTS = [self::DESKTOP, self::MOBILE];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'attachment_id' => 'integer',
|
||||
'crop_horizontal' => 'array',
|
||||
'crop_vertical' => 'array',
|
||||
'cropped_attachment_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function attachment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Attachment::class);
|
||||
}
|
||||
|
||||
public function croppedAttachment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Attachment::class, 'cropped_attachment_id');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user