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 MaatwebsiteLaravelNovaExcelActionsDownloadExcel action to your actions() list.

<?php

namespace AppNova;

use IlluminateHttpRequest;
use MaatwebsiteLaravelNovaExcelActionsDownloadExcel;

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  IlluminateHttpRequest $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.



Sumber: Laravel Blog