Excel Export for Laravel Nova

News

October 2nd, 2018

nova-excel.png

A common feature request from clients is the ability to export data to Excel, so they can create their own reports and a myriad of other things. Maatwebsite, the creators of Laravel Excel, recently launched a new Nova package named Laravel Nova Excel for just this purpose.

Integrating it with your Nova is really simple. First, require the package:

1composer require maatwebsite/laravel-nova-excel

Next, go to a Nova resource. As an example app/Nova/User.php. Add Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel action to your actions() list.

1<?php
2
3namespace App\Nova;
4
5use Illuminate\Http\Request;
6use Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel;
7
8class User extends Resource
9{
10 /**
11 * The model the resource corresponds to.
12 *
13 * @var string
14 */
15 public static $model = 'App\\User';
16
17 // Other default resource methods
18
19 /**
20 * Get the actions available for the resource.
21 *
22 * @param \Illuminate\Http\Request $request
23 *
24 * @return array
25 */
26 public function actions(Request $request)
27 {
28 return [
29 new DownloadExcel(),
30 ];
31 }
32}

After this, you’ll get the ability to export all the Users to an Excel file. Of course, this is just the minor highlights of the package and it can do many other things. Check out their getting started guide for full details on everything you might need.

Filed in:

Eric L. Barnes

Eric is the creator of Laravel News and has been covering Laravel since 2012.