MyExport.php 661 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. namespace App\Exports;
  3. use Maatwebsite\Excel\Facades\Excel;
  4. class MyExport {
  5. public $base1_path = '/app';
  6. public $base2_path = '/excel';
  7. public function commonExport($data,$path = ''){
  8. if(empty($path)) $path = date('YmdHis').rand(1000,9999).'.xlsx';
  9. $param = $data;
  10. $export = new CommonExport($param);
  11. $date = date('Ymd');
  12. $path = $date.'/'.$path;
  13. Excel::store($export, $path);
  14. return ['file'=>$this->base2_path.'/'.$path];
  15. }
  16. public function excelDownload($file){
  17. return response()->file(storage_path().$this->base1_path.$this->base2_path.'/'.$file);
  18. }
  19. }