public function showCsv($id)
{
// should top timeouts on long queries
set_time_limit(0);
$opts = $this->getOptions();
$model = $this->repo->show($id, $opts);
return IlluminateResponse::stream(function () use($model, $opts) {
if (ob_get_level() == 0) {
ob_start();
}
// Outputs the field names (column headers).
echo implode(',', array_map(function ($field) {
return $field['to'];
}, $model->fields)) . "\n";
// Outputs the statements (rows).
$this->repo->export($model, array_merge($opts, ['next' => function () {
echo "\n";
flush();
ob_flush();
}, 'stream' => function ($obj) {
// Outputs the field values (column values).
echo implode(',', array_map(function ($value) {
return $this->quoteCSV($value);
flush();
ob_flush();
}, $obj));
}]));
}, 200, ['Content-Type' => 'text/csv']);
}