Reputation: 4128
So I have weird problem, using Laravel Excel and importing some data. I want to split import by chunks, but every time I define chunk size it skip 1 record from every chunk.
Here is peace of code:
Excel::selectSheets('Sheet1')->load($tmp_path)->chunk(3,function($result) use ($product)
foreach ($result as $row ) {
$row->dump();
}
});
So I just splitting collection by 3 records to demonstrate problem, screen bellow
Update:
'import' => [
'heading' => false,
'startRow' => 3
]
So if I define startRow I will see desired number of items per chunk, but unnecessary data at the beginning...
Upvotes: 2
Views: 1712
Reputation: 4128
Well it's seams that https://github.com/Maatwebsite/Laravel-Excel have some problems with chunk method so I used Laravel chunk instead like this:
$tmp_path = $request->file('import_data')->getRealPath();
$results = Excel::load($tmp_path)->get();
$chunks = $results->chunk(3);
$chunks->toArray();
foreach ($chunks as $rows )
{
foreach ($rows as $row)
{
$row->dump();
}
}
Upvotes: 2