public function getCsvFile() { \DB::connection()->disableQueryLog(); $tmpName = tempnam(storage_path() . 'csv', 'csv'); $csvFile = new \Keboola\Csv\CsvFile($tmpName); $csvFile->writeRow(array_values($this->csv_columns)); // Determine how many chunks to get $limit = 1000; $count = $this->query->count(); $chunks = ceil($count / $limit); for ($i = 0; $i < $chunks; $i++) { $this->query->take($limit)->skip($i * $limit); $data = $this->query->get(); foreach ($data as $row) { $csvRow = array(); foreach (array_keys($this->csv_columns) as $field) { $csvRow[] = $this->getColumnData($row, $field); } $csvFile->writeRow($csvRow); } } return $tmpName; }