This tutorial helps you understand how to comfortably import export excel or CSV file to Database with Laravel 7

If you want to create easy import and export, excel file functionality, this laravel 7 maatwebsite/excel tutorial is best for you.

At the end of this tutorial, you will be able to download or import excel & CSV file directly from the database in laravel 7 application, respectively.

Generically, we will follow all the imperative that are needed to build a general laravel application. We will go from point a to b, something like creating or importing data to xls or CSV.

Laravel 7 Import Export Excel & CSV File to Database Example

Preferably, we will use a maatwebsite/excel composer plugin for exporting and importing data, most importantly, to interact with the database.

I will share the working pattern with you. Ideally, how should you import-export and download the excel & CSV file from the database using the  composer plugin. Follow the given below steps that will take you to the learning dimension.

Download Laravel Application

Let’s evoke this tutorial with the imperative step; installing a brand new laravel application offers us a key to opening the many opportunities. We can create the app from the beginning, build multiple features with it.

You can skip this step if you’ve already installed the app. Otherwise, put the command into effect to download the sacred canon.

composer create-project laravel/laravel laravel-excel-csv --prefer-dist

Later on, after the project installation, execute the command to enter the project directory.

cd laravel-excel-csv

Compose Database Connection

Make the consensus between laravel app and MySQL database, append the following code in .env file.

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel
DB_USERNAME=root
DB_PASSWORD=

Install Excel (maatwebsite) Pacakage

Commonly, to complete our foundational work, we require a third-party package. Ideally, we are talking about the Laravel-Excel plugin by Maatwebsite. It provides the robust mechanism to deal with Excel exports and imports in Laravel. In response, It has got the immense love of artisan’s on GitHub.

Run command to install the package.

composer require maatwebsite/excel

Register Plugin’s Service in Providers & Aliases

You can have the following code placed inside the config/app.php file.

'providers' => [
  .......
  .......
  .......
  Maatwebsite\Excel\ExcelServiceProvider::class,

 ],  

'aliases' => [ 
  .......
  .......
  .......
  'Excel' => Maatwebsite\Excel\Facades\Excel::class,

], 

Execute the vendor, publish command, and publish the config.

php artisan vendor:publish --provider="Maatwebsite\Excel\ExcelServiceProvider"

This will formulate a new config file as config/excel.php.

#laravel #excel #csv #laravel 7

Laravel 7 Import Export Excel & CSV File Tutorial with Example
88.15 GEEK