level === 0))) { abort(403); } ProfileAuthorizationHelper::authorize($profile); if (!Gate::allows('export polls')) { abort(403); } Log::info('Poll results exported', ['poll_id' => $poll->id, 'user_id' => auth('web')->id()]); $csv = new ResultsCsv($poll, App::getLocale()); $filename = 'poll-' . $poll->id . '-results-' . now()->format('Y-m-d') . '.csv'; return response()->streamDownload(function () use ($csv) { $out = fopen('php://output', 'w'); fwrite($out, "\xEF\xBB\xBF"); // UTF-8 BOM, so Excel shows accents correctly fputcsv($out, $csv->header()); foreach ($csv->rows() as $row) { fputcsv($out, $row); } fclose($out); }, $filename, ['Content-Type' => 'text/csv; charset=UTF-8']); } }