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:
@@ -3,6 +3,7 @@
|
||||
namespace App\Domains\Tenant\Resources;
|
||||
|
||||
use App\Domains\Attachable\Models\Attachment;
|
||||
use App\Domains\Attachable\Models\AttachmentCrop;
|
||||
use App\Domains\Catalog\Models\Category;
|
||||
use App\Domains\Menu\Models\Menu;
|
||||
use App\Domains\Tenant\Models\Tenant;
|
||||
@@ -98,7 +99,18 @@ class TenantResource extends JsonResource
|
||||
private function formatExtraConfig(mixed $value): mixed
|
||||
{
|
||||
if ($value instanceof Attachment) {
|
||||
return ($value->croppedAttachment ?? $value)->getTemporaryUrl(1440);
|
||||
$crops = $value->cropVariants->keyBy('variant');
|
||||
$desktop = $crops->get(AttachmentCrop::DESKTOP)?->croppedAttachment ?? $value;
|
||||
$mobile = $crops->get(AttachmentCrop::MOBILE)?->croppedAttachment ?? $desktop;
|
||||
|
||||
if ($crops->isEmpty()) {
|
||||
return $value->getTemporaryUrl(1440);
|
||||
}
|
||||
|
||||
return [
|
||||
'desktop' => $desktop->getTemporaryUrl(1440),
|
||||
'mobile' => $mobile->getTemporaryUrl(1440),
|
||||
];
|
||||
}
|
||||
|
||||
if (! is_array($value)) {
|
||||
|
||||
Reference in New Issue
Block a user