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