key) { $attachment->key = (string) Str::uuid(); } }); } protected function casts(): array { 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 Storage::disk('s3')->temporaryUrl( $this->path, now()->addMinutes($expiresInMinutes) ); } }