Member-only story

Laravel-Excel — P9: Exports

Dino Cajic
2 min readOct 10, 2022
Dino Cajic on Laravel Excel Exports

I think we’ve gotten to a good point with Imports in the previous 8 articles. It’s time to switch to exporting data into Excel sheets. Laravel-Excel is pretty amazing. It simplifies all of this for us.

Since we’ve been working with our User model this whole time, let’s create a quick export. First thing is to create our Exporter and specify that we want to use the User model.

php artisan make:export UsersExport --model=User

This generates a new file and a new directory under the app directory called app/Exports/UsersExport.php.

As you can see, it returns all of our users as a collection. We now have to call the export. We’ll create our export_users method in our UserController and then create a route that calls that method.

--

--

Dino Cajic
Dino Cajic

Written by Dino Cajic

Author of An Illustrative Introduction to Algorithms. IT Leader with a B.S. in Computer Science, a minor in Biology, and a passion for learning.

No responses yet