has('send_email') && $request->get('send_email')) { SendToAdmin::dispatch(auth()->user()->company(),$request->all(),ProfitLoss::class,$this->filename); return response()->json(['message' => 'working...'], 200); } // expect a list of visible fields, or use the default $pnl = new ProfitLoss(auth()->user()->company(), $request->all()); $pnl->build(); $csv = $pnl->getCsv(); $headers = array( 'Content-Disposition' => 'attachment', 'Content-Type' => 'text/csv', ); return response()->streamDownload(function () use ($csv) { echo $csv; }, $this->filename, $headers); } }