$document, 'settings' => auth()->guard('vendor')->user()->company->settings, 'sidebar' => $this->sidebarMenu(), 'company' => auth()->guard('vendor')->user()->company, ]); } private function sidebarMenu() :array { $enabled_modules = auth()->guard('vendor')->user()->company->enabled_modules; $data = []; // TODO: Enable dashboard once it's completed. // $this->settings->enable_client_portal_dashboard // $data[] = [ 'title' => ctrans('texts.dashboard'), 'url' => 'client.dashboard', 'icon' => 'activity']; if (self::MODULE_PURCHASE_ORDERS & $enabled_modules) { $data[] = ['title' => ctrans('texts.purchase_orders'), 'url' => 'vendor.purchase_orders.index', 'icon' => 'file-text']; } // $data[] = ['title' => ctrans('texts.documents'), 'url' => 'client.documents.index', 'icon' => 'download']; return $data; } 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); /** @var \App\Models\Document $document */ $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) { /** @var \Illuminate\Database\Eloquent\Collection $documents */ $documents = Document::whereIn('id', $this->transformKeys($request->file_hash)) ->where('company_id', auth()->guard('vendor')->user()->company_id) ->get(); $zipFile = new \PhpZip\ZipFile(); try { foreach ($documents as $document) { $zipFile->addFile(TempFile::path($document->filePath()), $document->name); } $filename = now().'-documents.zip'; $filepath = sys_get_temp_dir().'/'.$filename; $zipFile->saveAsFile($filepath) // save the archive to a file ->close(); // close archive return response()->download($filepath, $filename)->deleteFileAfterSend(true); } catch (\PhpZip\Exception\ZipException $e) { // handle exception } finally { $zipFile->close(); } } }