$document, ]); } public function download(ShowDocumentRequest $request, Document $document) { return Storage::disk($document->disk)->download($document->url, $document->name); } public function publicDownload(string $document_hash) { MultiDB::documentFindAndSetDb($document_hash); $document = Document::where('hash', $document_hash)->firstOrFail(); $headers = []; if(request()->input('inline') == 'true') $headers = array_merge($headers, ['Content-Disposition' => 'inline']); return Storage::disk($document->disk)->download($document->url, $document->name, $headers); } public function downloadMultiple(DownloadMultipleDocumentsRequest $request) { $documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) ->where('company_id', auth()->guard('contact')->user()->company->id) ->get(); $documents->map(function ($document) { if (auth()->guard('contact')->user()->client->id != $document->documentable->id) { abort(401, 'Permission denied'); } }); $options = new Archive(); $options->setSendHttpHeaders(true); $zip = new ZipStream(now() . '-documents.zip', $options); foreach ($documents as $document) { $zip->addFileFromPath(basename($document->diskPath()), TempFile::path($document->filePath())); } $zip->finish(); } }