Iterates .csv
file.
- $fileName - string, path to
.csv
file;
Get csv line as associative array.
- $columns - array with csv file's columns;
Return iterable object.
Example:
$csv = new \RonasIT\Support\Iterators\CsvIterator('/tmp/1.csv');
$csv->parseColumns(['id', 'name']);
foreach ($csv->getGenerator() as $line) {
dump($line);
}
//['order_index' => '1', 'name' => 'first']
//['order_index' => '2', 'name' => 'second']
//['order_index' => '3', 'name' => 'third']
Iterate results of the database query via chunk logic.
- $query - QueryBuilder object;
- $itemsPerPage - integer, chunk size.
$query = \App\Models\Category::orderBy('created_at', 'DESC');
foreach($iterator->getGenerator() as $category) {
dump($category);
}
//['id' => 1, 'name' => 'first', 'created_at' => '2018-01-23 07:20:06']
//['id' => 5, 'name' => 'second', 'created_at' => '2018-01-23 07:20:06']