In this episode, we focus on how to queue up exports (and imports) in Laravel, especially when using the Laravel Excel package. We start off by discussing different options for queue drivers, and then dive into setting up Redis along with Laravel Horizon to give us a nice dashboard for monitoring our queued jobs.
We walk through installing and configuring Redis as our queue connection, update our .env
accordingly, and then get Laravel Horizon set up via Composer. Once that's done, we touch on configuring Horizon for different environments, but since we're working locally, we stick to the default setup for now.
From there, we explore how queuing works with Laravel Excel. The best part? It already supports queuing out of the box! Instead of using store
to save your export, you simply use the queue
method, and the whole process works in the background. If you're working with large datasets, you can also customize how the data is chunked for more efficient processing.
We do a test run-exporting a small number of records first, then ramp things up by exporting a whopping 100,000 records to really show off the benefits of queuing. While that's chugging away, we also look at Laravel Excel's Exportable
trait—a handy way to streamline your export logic further.
Finally, after the big export is done, we confirm everything worked smoothly and preview the massive exported file. There's a quick teaser about how we'll surface export progress to users in a future episode, but for now, you've seen how to offload big exports to the queue and monitor them in Horizon.