locations = $locations; } public function export(string $filename): void { header("Content-Type: text/csv; charset=utf-8"); header("Content-Disposition: attachment; filename=$filename"); $handle = fopen("php://output", "wb"); fputcsv($handle, [ "ID", "Internal ID", "City", "Legal Entity", "Region", "Area Manager", "Area Manager Email", "Open", "Close", "Name", "Address", "Postcode", "Email", "Latitude", "Longitude", "Archived", "Closed", ]); foreach($this->locations as $location) { fputcsv($handle, [ $location->id, $location->internal_id, $location->city, $location->legal_entity_name, $location->region, $location->area_manager, $location->area_manager_email, "", "", $location->name, $location->address_1, $location->postal_code, $location->email, $location->latitude, $location->longitude, $location->archived, $location->closed, ]); } fclose($handle); } }