PHPackages                             dutchcodingcompany/csv-collection - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. dutchcodingcompany/csv-collection

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dutchcodingcompany/csv-collection
=================================

Read and write large csv files using Laravel's Illuminate Collections

1.4.0(11mo ago)117.5k↓47.6%4MITPHPPHP ^7.4|^8.0

Since Dec 15Pushed 11mo ago3 watchersCompare

[ Source](https://github.com/DutchCodingCompany/csv-collection)[ Packagist](https://packagist.org/packages/dutchcodingcompany/csv-collection)[ Docs](https://dutchcodingcompany.com)[ RSS](/packages/dutchcodingcompany-csv-collection/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (2)Versions (11)Used By (0)

CSV Collection
==============

[](#csv-collection)

[![Latest Version on Packagist](https://camo.githubusercontent.com/948402f86ef75800939cc67dfcb35251ecd4aed20b1e0ee7d4e873cd3dad470e/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6475746368636f64696e67636f6d70616e792f6373762d636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dutchcodingcompany/csv-collection)[![Total Downloads](https://camo.githubusercontent.com/74f05a6e959624d853809473caac68fe7e7a9706d0d5ba6a68e865a46c8cf29f/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6475746368636f64696e67636f6d70616e792f6373762d636f6c6c656374696f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/dutchcodingcompany/csv-collection)

This package provides a simple but powerful way to read and write large CSV files using the power of Laravel's lazy collections.

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require dutchcodingcompany/csv-collection
```

Usage
-----

[](#usage)

You may create a collection using the `new` keyword or the `make` method.

```
CsvCollection::make();
```

This gives you access to all [Collection](https://laravel.com/docs/8.x/collections#available-methods)and [Lazy Collection](https://laravel.com/docs/8.x/collections#lazy-collection-methods) methods.

### Open

[](#open)

To open a file and load it's content into a new collection you may use the `open` method on the collection.

```
use DutchCodingCompany\CsvCollection\CsvCollection;

CsvCollection::make()
    ->open('path/to/file.csv')
    ->count();
```

### Save

[](#save)

To save the collection items to a file you may use the `save` method on the collection.

```
use DutchCodingCompany\CsvCollection\CsvCollection;

CsvCollection::make(static function () {
    yield [
        'key' => 'value',
    ];
})
    ->save('path/to/file.csv');
```

#### Model exports

[](#model-exports)

When exporting models a memory efficient method is to lazily iterate through the models and `yield` it's content.

```
use DutchCodingCompany\CsvCollection\CsvCollection;

CsvCollection::make(static function () {
    $models = Model::query()->lazy();

    foreach ($models as $model){
        yield $model->only([
            'id',
            //
        ]);
    }
})
    ->save('path/to/file.csv');
```

### Options

[](#options)

The following options are available to suit your needs:

- `header`, default: `true`
- `delimiter`, default: `,`
- `enclosure`, default: `"`
- `escape`, default: `\\`

These options could be passed to the `open` and `save` methods, be set using the `options` method, or be set as the global default using the static `defaults` method.

The delimiter can be detected for a file by using the `detectDelimiter` method like this:

```
CsvCollection::detectDelimiter($path);

```

#### Header

[](#header)

When using a header, lines will contain an associated array. Otherwise, lines will contain an indexed array.

```
// Without header
[
    0 => 'John',
    1 => 'Doe',
]

// With header
[
    'first_name' => 'John',
    'last_name' => 'Doe',
]
```

***Note**: When saving a collection to a file the keys of the first element in the collection will be used as the header.*

Testing
-------

[](#testing)

```
composer test
```

Credits
-------

[](#credits)

- [Bjorn Voesten](https://github.com/bjornvoesten)
- [Dutch Coding Company](https://github.com/dutchcodingcompany)
- [All contributors](https://github.com/dutchcodingcompany/csv-collection/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

45

—

FairBetter than 93% of packages

Maintenance50

Moderate activity, may be stable

Popularity33

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~180 days

Recently: every ~293 days

Total

10

Last Release

356d ago

Major Versions

0.0.1 → 1.0.02020-12-15

PHP version history (2 changes)0.0.1PHP ^7.4

1.0.1PHP ^7.4|^8.0

### Community

Maintainers

![](https://www.gravatar.com/avatar/253e8fe87efe50428e19537de8f0753d21cdb8dae3a271ad27ef805b9ab0d292?d=identicon)[marcoboers](/maintainers/marcoboers)

![](https://avatars.githubusercontent.com/u/100052?v=4)[Tom Janssen](/maintainers/dododedodonl)[@dododedodonl](https://github.com/dododedodonl)

![](https://avatars.githubusercontent.com/u/10741416?v=4)[Bjorn Voesten](/maintainers/bjornvoesten)[@bjornvoesten](https://github.com/bjornvoesten)

![](https://www.gravatar.com/avatar/a17eeb9b88a4cbaf228dcf25c7f27eda952484372dc960b64272f37b2865a59f?d=identicon)[dutchcodingcompany](/maintainers/dutchcodingcompany)

---

Top Contributors

[![bjornvoesten](https://avatars.githubusercontent.com/u/10741416?v=4)](https://github.com/bjornvoesten "bjornvoesten (5 commits)")[![bjorn-dcc](https://avatars.githubusercontent.com/u/106660058?v=4)](https://github.com/bjorn-dcc "bjorn-dcc (2 commits)")[![bramr94](https://avatars.githubusercontent.com/u/24361182?v=4)](https://github.com/bramr94 "bramr94 (2 commits)")[![marcoboers](https://avatars.githubusercontent.com/u/3316595?v=4)](https://github.com/marcoboers "marcoboers (2 commits)")[![ThijsLacquet](https://avatars.githubusercontent.com/u/28624985?v=4)](https://github.com/ThijsLacquet "ThijsLacquet (2 commits)")

---

Tags

csvlaravellazy-collectionsphplaravelcsvcollectionilluminatedccdutch coding companycsv collection

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dutchcodingcompany-csv-collection/health.svg)

```
[![Health](https://phpackages.com/badges/dutchcodingcompany-csv-collection/health.svg)](https://phpackages.com/packages/dutchcodingcompany-csv-collection)
```

###  Alternatives

[cerbero/lazy-json

Framework-agnostic package to load JSONs of any dimension and from any source into Laravel lazy collections.

254309.8k1](/packages/cerbero-lazy-json)[pragmarx/ia-collection

Laravel Illuminate Agnostic Collection

473.4M2](/packages/pragmarx-ia-collection)[gamez/typed-collection

Type-safe collections based on Laravel Collections

45317.8k](/packages/gamez-typed-collection)[mindtwo/native-enum

Package for using native php enums.

2626.0k1](/packages/mindtwo-native-enum)[werxe/laravel-collection-macros

Custom Laravel Collection macros.

2625.8k](/packages/werxe-laravel-collection-macros)[iteks/laravel-enum

A comprehensive Laravel package providing enhanced enum functionalities, including attribute handling, select array conversions, and fluent facade interactions for robust enum management in Laravel applications.

2516.7k](/packages/iteks-laravel-enum)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
