key) { $attachment->key = (string) Str::uuid(); } }); } protected function casts(): array { return [ 'type' => AttachmentType::class, 'size' => 'integer', ]; } public function cropVariants(): HasMany { return $this->hasMany(AttachmentCrop::class); } public function desktopCrop(): HasOne { return $this->hasOne(AttachmentCrop::class) ->where('variant', AttachmentCrop::DESKTOP); } public function mobileCrop(): HasOne { return $this->hasOne(AttachmentCrop::class) ->where('variant', AttachmentCrop::MOBILE); } public function cropSource(): HasOne { return $this->hasOne(AttachmentCrop::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) ); } }