Introducing Laravel Nova Excel 🚀

Maatwebsite
Aug 30, 2018 · 3 min read

At Maatwebsite we love Laravel! Of course we couldn’t wait to get our hands on Laravel Nova! We can tell you… the wait was worth it! Considering our primary open source focus is Laravel Excel, we couldn’t stay behind and now introduce you Laravel Nova Excel.

Image for post
Image for post

🚀 5 Minute quick start

Laravel Nova Excel integrates Laravel Nova resources and Laravel Excel seamlessly. Integration is as easy as adding one class to your list of resource actions!

Before integrating this package, make sure you have Laravel Nova installed. Then install maatwebsite/laravel-nova-excel via composer. This will download the package and Laravel-Excel.

composer require maatwebsite/laravel-nova-excel

Go to your Nova resource. As example we’ll use the 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(),
];
}
}

Go to your resource in your Nova admin panel, select all or some users and click “Download Excel”.

Image for post
Image for post

In your downloads folder you will find your users.xlsx! The name of the file is auto-generated based on the plural form of the resource name. But of course this is fully configurable!

public function actions(Request $request)
{
return [
(new DownloadExcel())->withFilename('users-2018.xlsx'),
];
}

Prefer your customer to choose the filename themselves? No problem! Use the askForFilename method to prompt a question after clicking “Download Excel”.

public function actions(Request $request)
{
return [
(new DownloadExcel())->askForFilename(),
];
}
Image for post
Image for post

As Laravel Nova Excel delegates all the heavy-lifting to Laravel Excel, it’s also possible to customize your entire export.

You can read more about it in our dedicated documentation: https://laravel-excel.maatwebsite.nl/nova/1.0/getting-started/

Do you need help with integrating Laravel (Nova) Excel or do you need help building a Laravel application? We are there to help you on a commercial basis. Contact us via info@maatwebsite.nl or via phone +31 (0)10 744 9312 to discuss the possibilities.

Written by Patrick Brouwers

Maatwebsite

Professional Software Development

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store