40 lines
1.1 KiB
PHP
40 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Actions\Reports\ExportEntryData;
|
|
use App\Http\Controllers\Controller;
|
|
use Illuminate\Support\Facades\App;
|
|
use Illuminate\Support\Facades\Response;
|
|
|
|
// TODO: Printing testing
|
|
/** @codeCoverageIgnore */
|
|
class ExportEntriesController extends Controller
|
|
{
|
|
public function __invoke()
|
|
{
|
|
$exporter = App::make(ExportEntryData::class);
|
|
$data = $exporter->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"',
|
|
]);
|
|
|
|
}
|
|
}
|