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:
@@ -35,6 +35,24 @@ class CroppedImageOrBase64Rule implements ValidationRule
|
||||
return;
|
||||
}
|
||||
|
||||
if (isset($value['crops']) && is_array($value['crops'])) {
|
||||
foreach (['desktop', 'mobile'] as $variant) {
|
||||
$crop = $value['crops'][$variant] ?? null;
|
||||
|
||||
if (! is_array($crop)) {
|
||||
$fail("The :attribute.crops.{$variant} field must be an object.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
$this->validateRange("{$attribute}.crops.{$variant}", 'crop_horizontal', $crop, $fail);
|
||||
$this->validateRange("{$attribute}.crops.{$variant}", 'crop_vertical', $crop, $fail);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// Backwards compatibility with the original single-crop payload.
|
||||
$this->validateRange($attribute, 'crop_horizontal', $value, $fail);
|
||||
$this->validateRange($attribute, 'crop_vertical', $value, $fail);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user