customerData; } /** * @param Collection $customerData * @return ViewExport */ public function setCustomerData(Collection $customerData) { $this->customerData = $customerData; return $this; } /** * {@inheritdoc} */ public function export() { $temp_path=$this->renderFile(); response()->download(Storage::disk('public') ->path($temp_path), $this->getFilename()) ->deleteFileAfterSend(true) ->send(); exit; } public function store() { return $this->renderFile(); } private function renderFile() { $view = $this->getView($this->getCustomerData()?:$this->getData(false)); $temp_path="temp/".$this->getFilename(); Storage::disk('public')->put($temp_path, $view->render()); return $temp_path; } /** * 设置文件名 * @return string */ abstract public function getFilename(): string ; /** * 渲染对应的视图 * @param Collection $data 导出的数据 * @return View */ abstract public function getView(Collection $data): View ; }