Is there a workaround to make large file exports work with Laravel-Excel (version 3.1)? All posts I saw here and on GitHub are old with no real solutions. The only solution is to increase memory_limit
in php.ini
. But I already have it at 2048M
.
Assuming I am using a collection:
class InvoicesExport implements FromCollection
{
public function collection()
{
return Invoice::all();
}
}
Is there any way to make it work? WithChunkReading
is only for imports, and does not work for exports: https://docs.laravel-excel.com/3.1/imports/chunk-reading.html#chunk-reading
2
Answers
You can try to implement
FromQuery
concern. Instead ofFromCollection
. In this way behind the scenes query is executed inchunks
.Try the code and see if it brings any difference.
Make sure to not use
->get()
the result.For reference you can look it here.
I advise you to try library FastExcelLaravel, it works very fast and uses a minimum of memory. And you don’t need to create additional classes to export models.