diff --git a/app/Http/Controllers/Admin/ExportEntriesController.php b/app/Http/Controllers/Admin/ExportEntriesController.php new file mode 100644 index 0000000..d569c0a --- /dev/null +++ b/app/Http/Controllers/Admin/ExportEntriesController.php @@ -0,0 +1,37 @@ +getData(); + // Create a callback to write the CSV data + $callback = function () use ($data) { + $file = fopen('php://output', 'w'); + + foreach ($data as $line) { + // Convert the string into an array + $fields = explode(',', $line); + // Write the array to the CSV file + fputcsv($file, $fields); + } + + fclose($file); + }; + + // Return a response with the CSV content + return Response::stream($callback, 200, [ + 'Content-Type' => 'text/csv', + 'Content-Disposition' => 'attachment; filename="audition_entries_export.csv"', + ]); + + } +}