Eloquent and Large Datasets: chunk, lazy and cursor | DevSense
How to process and export hundreds of thousands of rows in Laravel without running out of memory: N+1 and preventLazyLoading, chunk vs chunkById, lazy and cursor, PDO buffering, CSV streaming, Query Builder and raw SQL for reports.