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