{"id":19422850,"url":"https://github.com/dutchcodingcompany/csv-collection","last_synced_at":"2025-04-24T15:32:26.476Z","repository":{"id":43040793,"uuid":"321787405","full_name":"DutchCodingCompany/csv-collection","owner":"DutchCodingCompany","description":"Read and write large CSV files using the power of Laravel's lazy collections","archived":false,"fork":false,"pushed_at":"2024-04-26T10:12:26.000Z","size":25,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-20T10:26:06.068Z","etag":null,"topics":["csv","laravel","lazy-collections","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DutchCodingCompany.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-12-15T20:57:52.000Z","updated_at":"2024-06-02T12:16:55.000Z","dependencies_parsed_at":"2024-04-26T11:27:24.673Z","dependency_job_id":"77ebd7e0-f001-4a08-80fa-9b67b4cfc712","html_url":"https://github.com/DutchCodingCompany/csv-collection","commit_stats":{"total_commits":5,"total_committers":4,"mean_commits":1.25,"dds":0.6,"last_synced_commit":"6f706e6155b7fbfd90fa0c27f0c5402d5cc546fa"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Fcsv-collection","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Fcsv-collection/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Fcsv-collection/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DutchCodingCompany%2Fcsv-collection/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DutchCodingCompany","download_url":"https://codeload.github.com/DutchCodingCompany/csv-collection/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250654497,"owners_count":21465894,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csv","laravel","lazy-collections","php"],"created_at":"2024-11-10T13:35:30.423Z","updated_at":"2025-04-24T15:32:26.250Z","avatar_url":"https://github.com/DutchCodingCompany.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# CSV Collection\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/dutchcodingcompany/csv-collection.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/csv-collection)\n[![Total Downloads](https://img.shields.io/packagist/dt/dutchcodingcompany/csv-collection.svg?style=flat-square)](https://packagist.org/packages/dutchcodingcompany/csv-collection)\n\nThis package provides a simple but powerful way to read and write large CSV files using the power of Laravel's lazy\ncollections.\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require dutchcodingcompany/csv-collection\n```\n\n## Usage\n\nYou may create a collection using the `new` keyword or the `make` method.\n\n```php \nCsvCollection::make();\n```\n\nThis gives you access to all [Collection](https://laravel.com/docs/8.x/collections#available-methods)\nand [Lazy Collection](https://laravel.com/docs/8.x/collections#lazy-collection-methods) methods.\n\n### Open\n\nTo open a file and load it's content into a new collection you may use the `open` method on the collection.\n\n```php\nuse DutchCodingCompany\\CsvCollection\\CsvCollection;\n\nCsvCollection::make()\n    -\u003eopen('path/to/file.csv')\n    -\u003ecount();\n```\n\n### Save\n\nTo save the collection items to a file you may use the `save` method on the collection.\n\n```php\nuse DutchCodingCompany\\CsvCollection\\CsvCollection;\n\nCsvCollection::make(static function () {\n    yield [\n        'key' =\u003e 'value',\n    ];\n})\n    -\u003esave('path/to/file.csv');\n```\n\n#### Model exports\n\nWhen exporting models a memory efficient method is to lazily iterate through the models and `yield` it's content.\n\n```php\nuse DutchCodingCompany\\CsvCollection\\CsvCollection;\n\nCsvCollection::make(static function () {\n    $models = Model::query()-\u003elazy();\n    \n    foreach ($models as $model){\n        yield $model-\u003eonly([\n            'id',\n            //\n        ]);\n    }\n})\n    -\u003esave('path/to/file.csv');\n```\n\n### Options\n\nThe following options are available to suit your needs:\n\n- `header`, default: `true`\n- `delimiter`, default: `,`\n- `enclosure`, default: `\"`\n- `escape`, default: `\\\\`\n\nThese options could be passed to the `open` and `save` methods, be set using the `options` method, or be set as the\nglobal default using the static `defaults` method.\n\nThe delimiter can be detected for a file by using the `detectDelimiter` method like this:\n\n```\nCsvCollection::detectDelimiter($path);\n```\n\n#### Header\n\nWhen using a header, lines will contain an associated array. Otherwise, lines will contain an indexed array.\n\n```php\n// Without header\n[\n    0 =\u003e 'John',\n    1 =\u003e 'Doe',\n]\n\n// With header\n[\n    'first_name' =\u003e 'John',\n    'last_name' =\u003e 'Doe',\n]\n```\n\n_**Note**: When saving a collection to a file the keys of the first element in the collection will be used as the\nheader._\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Credits\n\n- [Bjorn Voesten](https://github.com/bjornvoesten)\n- [Dutch Coding Company](https://github.com/dutchcodingcompany)\n- [All contributors](https://github.com/dutchcodingcompany/csv-collection/graphs/contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutchcodingcompany%2Fcsv-collection","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdutchcodingcompany%2Fcsv-collection","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdutchcodingcompany%2Fcsv-collection/lists"}