How to import data from excel file to database table in laravel 5

Published Date: 25-Nov-2017 | Tags: Laravel 5.5  Import / Export  

This tutorial I want to show you an easy way to import data from excel by using laravel and maatwebsite/excel.

Step 1: Install maatwebsite/excel package.

To install it, please go to terminal or command prompt (for window users), navigate to your project directory, and run this command.

composer require maatwebsite/excel

 

Step 2: Excel File Template

To be able to import data from excel, you need to know

  • File name
  • Sheet name
  • File Template ( the first row of excel file is column name)

import-from-excel-laravel

 

Step 3: How to Import from Excel File

Below is the code of importing data from excel file and save to customer table.

Excel::selectSheets('Sheet 1')->load('Customer.xlsx', function ($reader) {
            Customer::insert($reader->toArray());
        });

Please check maatwebsite/excel website http://www.maatwebsite.nl/laravel-excel/docs for more info.

Hope you can do it.



Related Posts

© 2018 All Rights Reserved.