拉拉维尔返回下载不起作用



我正在尝试创建Excel CSV工作表,然后下载它。

CSV文件创建完美,但不幸的是下载不起作用。

public function download_csv(Request $request) {
        if ($request->isMethod('post')) {
            if (Auth::check()) {
             $user_id = Auth::id();
             $customer_id = Auth::user()->customer_id;
             $suppliers = Supplier::where('is_active', 1)->get();
             $dataCSV = array();
             $main = array();
             $cnt = 1;
             foreach($suppliers as $m) {
                $main['S. No'] = $cnt++;
                $main['Name'] = $m->Name;
                array_push($dataCSV, $main);
                $cnt++;
             }
             $csv_name = $user_id.'_'.rand(10000, 99999);
             $csv =  Excel::create($csv_name, function($excel) use($dataCSV) {
                $excel->sheet('Sheetname', function($sheet) use($dataCSV) {
                   $sheet->fromArray($dataCSV);
                });
             });
             $csv->store('csv', storage_path('excel/exports/'.$customer_id.'/'));
             $file = storage_path('excel/exports/'.$customer_id.'/'.$csv_name.'.csv');
            $headers = array(
                'Content-Type: application/csv',
              );
            return Response::download($file, $user_id.'.csv', $headers);
          }
        }
    }

我不明白问题出在哪里。

任何帮助将不胜感激。

谢谢

你用过响应类吗? use IlluminateSupportFacadesResponse;

选项 2:尝试通过其他方法下载它: return response()->download($pathToFile, $name, $headers);

https://laravel.com/docs/5.4/responses#file-downloads

最新更新