In this tutorial, I would like to share with you step by step import excel or csv to store in database and how to export or download excel or csv file from database using maatwebsite package in laravel 5.6 application.
Maatwebsite packages through you can easily get data, also you can group by data, also create more then one sheet etc. so now i show you simple example of items table data, you can download in xls, xlsx and csv formate and also you import data in xls, xlsx and csv formate file.
In this example, you have to just follow few step to implement import and export both function in your project. First see your browser preview will become like this:
In this step we have to create migration for items table using Laravel 5.6 php artisan command, so first fire bellow command:
php artisan make:migration create_items_table
After this command you will find one file in following path "database/migrations" and you have to put bellow code in your migration file for create items table.
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateItemsTable extends Migration
* Run the migrations.
* @return void
public function up()
Schema::create('items', function (Blueprint $table) {
$table->increments('id');
$table->string('title');
$table->text('description');
$table->timestamps();
* Reverse the migrations.
* @return void
public function down()
Schema::drop("items");
After create "items" table you should create Item model for items, so first create file in this path "app/Item.php" and put bellow content in item.php file:
app/Item.php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Item extends Model
public $fillable = ['title','description'];
Step 4: Add Routes
In this step, we need to create route of import export file. so open your "routes/web.php" file and add following route.
In this step, now we should create new controller as MaatwebsiteDemoController in this path "app/Http/Controllers/MaatwebsiteDemoController.php". this controller will manage all impostExport, downloadExcel and importExcel request and return response, so put bellow content in controller file:
return back()->with('success', 'Insert Record successfully.');
Step 6: Create Blade File
In Last step, let's create importExport.blade.php(resources/views/importExport.blade.php) for layout and we will write design code here and put following code:
I'm a full-stack developer, entrepreneur and owner of ItSolutionstuff.com. I
live in India and I love to
write tutorials and tips that can help to other artisan. I am a big fan of PHP, Laravel, Angular, Vue, Node, Javascript, JQuery,
Codeigniter and Bootstrap from the early stage. I believe in Hardworking and Consistency.