fileName; } /** * @return bool */ public function run(): bool { // 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: /** @var Entry $first */ $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); return true; } private function tempFile() { $this->fileName = $this->job->key . '-records.csv'; } }