Published in · 7 min read · Sep 21, 2021
--
In this series of articles, I am going to show how you can easily read and import data from a csv file or excel into your database and export data into a csv file or excel using Laravel in your Laravel API or web application. There are myriads of scenarios in which you would want to do this in your application. For instance, suppose you need to register a set of students in your school management application or you need to onboard some professionals for a scheme. You can easily do it on a one by one basis. However, if the records to be added are hom*ogenous and in their tens or hundreds or even thousands, performing this task manually can be very tasking, laborious and a waste of time. Not forgetting the fact that it is not so good for the user experience. Ultimately, as a programmer, devising solutions to these sorts of problems should be one of your greatest assets.
Due to ease of setting up, I will be using a REST API service in this tutorial. It works exactly the same way for a web application.
As mentioned above, this is going to be a series. In this first part, I will be showing how to import data from a csv or excel file without any package or plug in. Just pure PHP / Laravel codes. Thereafter I am going to do the same using a Laravel plugin. And in the third part, I am going to show how to export the data back to a csv or excel file.
Prerequisite
- Basic knowledge of PHP / Laravel