fileName; } /** * */ public function run() { // create temporary file: $this->tempFile(); // necessary for CSV writer: $fullPath = storage_path('export') . DIRECTORY_SEPARATOR . $this->fileName; // create CSV writer: $writer = Writer::createFromPath(new SplFileObject($fullPath, 'a+'), 'w'); // all rows: $rows = []; // add header: $first = $this->getEntries()->first(); $rows[] = array_keys(get_object_vars($first)); // then the rest: /** @var Entry $entry */ foreach ($this->getEntries() as $entry) { $rows[] = array_values(get_object_vars($entry)); } $writer->insertAll($rows); } private function tempFile() { $this->fileName = $this->job->key . '-records.csv'; } }