document = $document; return $this; } public function getUrl(): ?string { $media = $this->evaluate($this->document); if ($media instanceof MediaCollection) { /** @var Media $document */ $document = $media->first(); return $document->getTemporaryUrl(Carbon::now()->addMinutes(5)); } return null; } #[On('download-document')] public function downloadFile() { $media = $this->evaluate($this->document); if ($media instanceof MediaCollection) { /** @var Media $document */ $stream = Storage::disk('s3')->readStream($media->first()->getPath()); $response = new StreamedResponse(function () use ($stream) { fpassthru($stream); }); dd($response); $response->headers->set('Content-Type', $this->getType()); $response->headers->set('Content-Disposition', 'attachment; filename="' . basename('document') . '"'); return $response; } return null; } public function getType(): ?string { $media = $this->evaluate($this->document); if ($media instanceof MediaCollection) { /** @var Media $document */ $document = $media->first(); return $document->getTypeFromMime(); } return null; } public function getDocumentId(): string { return 'document-' . Str::random(12); } }