Handling CSV file uploads is a common feature in many web applications, especially dashboards and admin panels. However, processing large CSV files during the request lifecycle can slow down your app. Instead, we can offload the heavy lifting to a background job using Laravel Queues.
Upload and store a CSV file
Dispatch a job to process the file asynchronously
Save the data into a database
Laravel 10+
Queue configured (e.g. database
, redis
, sqs
)
A simple database table to insert records
database
driver, configure .env
:Create the queue tables:Then run the queue worker:✅ Example CSV FormatMake sure your CSV is in this format:You can follow the next steps to improve it by:Adding try/catch
in the job
Logging errors
Using Laravel’s failed()
method on the job class
Adding progress tracking in the database
ProcessCsv
to handle errors and update progress.🚀 ConclusionProcessing CSV files in the background using Laravel Queues ensures your application stays responsive and scalable. This technique is perfect for bulk imports and large data operations.