Laravel 5.6 Data Export to CSV and Excel Example

Today, We want to share with you Laravel 5.6 Data Export to CSV and Excel Example.In this post we will show you Import & Export Data in CSV in Laravel 5.6, hear for Excel and csv import export using maatwebsite in laravel 5.6 we will give you demo and example for implement.In this post, we will learn about Exporting Data to Excel with Laravel 5.6 and MySQL with an example.

Laravel 5.6 Data Export to CSV and Excel Example

There are the Following The simple About Laravel 5.6 Data Export to CSV and Excel Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Laravel 5.6 Import Export to Excel and CSV example, so the some major files and Directory structures for this example is following below.

  • Download Laravel 5.6
  • Configure Database
  • Install Package maatwebsite
  • Laravel providers and aliases
  • Publish Config
  • Laravel 5.6 Model and Migration
  • Make view file
  • Laravel 5.6 controller and route
  • Make export function in MemberController.

Laravel 5.6 Data Export to CSV and Excel Example

Step 1: Download Laravel 5.6 Project

$ composer create-project --prefer-dist laravel/laravel memberdata

Step 2: Configure SQL Database


And then I can setup config file set database credentials.

[email protected]

Step 3: Install maatwebsite Package

composer require maatwebsite/excel

Step 4: Define Laravel providers and aliases

providers in config >> app.php

'providers' => [

Laravel 5.6 aliases in config >> app.php

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

Step 5: Laravel Publish Config

php artisan vendor:publish

Step 6: Make a Model and Migration

 php artisan make:model Member -m

create__members_table migration file.

 public function up()
        Schema::create('members', function (Blueprint $table) {

step 7: Make a view file

resources >> views >> member.blade.php

<!DOCTYPE html>
    <meta charset="utf-8">
    <title>Laravel 5.6 Export To Csv and Excel Download</title>
    <link rel="stylesheet" href=""/>
    <div class="pakainfo container">
      <div class="pakainfo row">
        <div class="col-md-4 pakainfo"></div>
        <div class="col-md-2 pakainfo">
          <form action="{{url('member/export')}}" enctype="multipart/form-data">
            <button class="btn btn-success" type="submit">Export</button>

Step 8: Make Laravel controller and route

php artisan make:controller MemberController

create a simple MemberController.php

Also Read This ๐Ÿ‘‰   subquery in sql


I register the Laravel route in a web.php main file.

Route::get('member', '[email protected]');
Route::get('member/export', '[email protected]');

Add source code simple to create() function to show view.



public function create()
        return view('member');

Step 9: An export function in MemberController.


The Best way to let’s start an export for CSV file is to make a custom export Laravel 5.6 class. I shall use a DataExport as simple an example.



namespace App\Exports;
use App\Member;

use Maatwebsite\Excel\Concerns\FromCollection;

class DataExport implements FromCollection
    public function collection()
        return Member::all();

In simple MemberController.php I can then step by step download this CSV/Excel file export.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Excel;
use App\Member;
use App\Exports\DataExport;

class MemberController extends Controller
    public function create()
        return view('member');
        public function exportFile()
         return Excel::download(new DataExport, 'data.xlsx');

Laravel 5.6 Data Export to CSV and Excel – Output

Angular 6 CRUD Operations Application Tutorials

Read :


You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 5.6 Data Export to CSV and Excel Example.
I would like to have feedback on my blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, donโ€™t forget to share.