Excel Export for Laravel Nova
Published on by Eric L. Barnes
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:
composer 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.
<?php namespace App\Nova; use Illuminate\Http\Request;use Maatwebsite\LaravelNovaExcel\Actions\DownloadExcel; class User extends Resource{ /** * The model the resource corresponds to. * * @var string */ public static $model = 'App\\User'; // Other default resource methods /** * Get the actions available for the resource. * * @param \Illuminate\Http\Request $request * * @return array */ public function actions(Request $request) { return [ new DownloadExcel(), ]; }}
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.
Eric is the creator of Laravel News and has been covering Laravel since 2012.