David Carr shows us how to import a 30,000 line CSV file in Laravel 5.

import csv files laravel

I recently had to import a 30,000 line CSV file, in this post, I document how I tackled this task.

large files can be read fairly easily with PHP the issue is when you start inserting the data into a database, even worse if you're first checking if the record already exists. In that case, say you're working with a 100 lined CSV file your end up doing 200 queries. You can't avoid needing to do the queries but doing lots in one go will use up your application's memory and will timeout when taking too long.