Integrating Maatwebsite Excel in Laravel Project.

Hey guys, this is my first blog post here. I want to share how to integrate excel in your Laravel project. There are couples of packages out there which provides this functionality but I will be using Maatwebsite Excel for this purpose.

This is a walk-through on how to integrate Maatwebsite Excel in Laravel application, please refer to documentation if you have any concern.

  1. Set Up.
    Package requirement
    - PHP version ^7.0
    - Laravel version ^5.5
    - PhpSpreadsheet version ^1.6.

Download the package in your project by running the code below.

However, Maatwebsite\Excel\ExcelServiceProvider is auto-discovered by default but you can do it yourself by Adding to the ServiceProvider in config/app.php

The Excel facade is also auto-discovered but you can add it yourself by adding the code below to the facade in config/app.php.

Lastly, to publish the config, run the vendor publish command:

This will create a new config file in the config/excel.php where you can make a lot of changes and configurations.

2. Import
There’s a lot you can do here. Please check the documentation for the available functions. I will be using import to collection here.

i). Import to Collection.
Create an import class in app/Imports by either running this command below

or manually by creating Imports directory in app, then ClassNameImport.php (i.e Imports\MovieImport.php) in Imports directory.

ii). Now create a method in the controller for the import.

3. Call this through the route

This will handle the excel import. I will write a second article on Maatwebsite Excel Export ASAP. If you have any error or issue, please reach out on Twitter @heavykenny or use the comment section. Thanks.



Back-end Developer

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store