Data Import to the database using CSV File in Laravel5.2

9:38 AM Unknown 4 Comments

Data importing in database using csv file in using laravel5.2 is quite easy. Today I spend some couple of minutes to learn about data import using csv file. How I did that work , I am gonna describe here.

At first i download the laravel project using composer, then i create the mysql database using phpmyadmin and I configure the database credentials in .env file. 

Now I just created the user.csv file inside of the public directory and add some comma separated values. These values is based on the user information whose table structure or migration file is provided by the laravel by default. The File is something like this

 


I just run the migration file using command php artisan migrate command and made some route configuration in routes.php file which is something like this.



In above figure shows that routing for the importing csv file, Here I am not using controller for the importing Because I created this project for learning purpose. In which fopen() function is used to open the user.csv file and fgetcsv() function is used to fetch data from csv file to store into database.

I can run this project using base_url/csv  then it will import all the data of user.csv file. and show all the result to the browser because it return the User::all() values. Thanks ! I learned it ! Keep On Working !!!!

4 comments: