Skip to content

Commit acadb03

Browse files
committed
Updated readme
1 parent 477841e commit acadb03

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

README.md

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,29 @@ To save the collection items to a file you may use the `save` method on the coll
4545
use DutchCodingCompany\CsvCollection\CsvCollection;
4646

4747
CsvCollection::make(static function () {
48-
//
48+
yield [
49+
'key' => 'value',
50+
];
51+
})
52+
->save('path/to/file.csv');
53+
```
54+
55+
#### Model exports
56+
57+
When exporting models a memory efficient method is to lazily iterate through the models and `yield` it's content.
58+
59+
```php
60+
use DutchCodingCompany\CsvCollection\CsvCollection;
61+
62+
CsvCollection::make(static function () {
63+
$models = Model::query()->lazy();
64+
65+
foreach ($models as $model){
66+
yield $model->only([
67+
'id',
68+
//
69+
]);
70+
}
4971
})
5072
->save('path/to/file.csv');
5173
```
@@ -80,7 +102,8 @@ When using a header, lines will contain an associated array. Otherwise, lines wi
80102
]
81103
```
82104

83-
_**Note**: When saving a collection to a file the keys of the first element in the collection will be used as the header._
105+
_**Note**: When saving a collection to a file the keys of the first element in the collection will be used as the
106+
header._
84107

85108
## Testing
86109

0 commit comments

Comments
 (0)