feat(attachment): add cropping functionality for images and update metadata storage
This commit is contained in:
@@ -6,6 +6,9 @@ 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\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
#[Fillable([
|
||||
@@ -16,6 +19,9 @@ use Illuminate\Support\Str;
|
||||
'mime_type',
|
||||
'extension',
|
||||
'size',
|
||||
'crop_horizontal_start_percent',
|
||||
'crop_vertical_start_percent',
|
||||
'cropped_attachment_id',
|
||||
])]
|
||||
class Attachment extends Model
|
||||
{
|
||||
@@ -37,15 +43,28 @@ class Attachment extends Model
|
||||
return [
|
||||
'type' => AttachmentType::class,
|
||||
'size' => 'integer',
|
||||
'crop_horizontal_start_percent' => 'float',
|
||||
'crop_vertical_start_percent' => 'float',
|
||||
'cropped_attachment_id' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function croppedAttachment(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(self::class, 'cropped_attachment_id');
|
||||
}
|
||||
|
||||
public function originalAttachment(): HasOne
|
||||
{
|
||||
return $this->hasOne(self::class, 'cropped_attachment_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the pre-signed temporary S3 URL for this attachment.
|
||||
*/
|
||||
public function getTemporaryUrl(int $expiresInMinutes = 10): string
|
||||
{
|
||||
return \Illuminate\Support\Facades\Storage::disk('s3')->temporaryUrl(
|
||||
return Storage::disk('s3')->temporaryUrl(
|
||||
$this->path,
|
||||
now()->addMinutes($expiresInMinutes)
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user