Learn to Build a Chatbot with Laravel and BotMan!
Laravel Excel 3.0
Laravel Packages / March 22, 2018

Laravel Excel 3.0

Laravel Excel is a package by Maatwebsite that makes working with spreadsheets easy. It’s been out since 2013 and just recently released version 3.0 with some important breaking changes.

In their lessons learned post they go through the history of the project and why they have decided to make v3.0 a major breaking change from previous releases:

My goal for Laravel Excel 3.0 is to cater our own needs first and only add convenience methods that we need and would use ourselves, instead of re-inventing the PhpSpreadsheet “wheel”. The less code to solve the problem, the easier it should be to maintain.

The post is worth checking out specifically to look at opensource from the maintainer’s point of view and how it’s easy to let people change your goals to suit them. This quote is so perfect:

Laravel Excel used to be an opinionated PHPExcel but became an un-opinionated Excel for Laravel.

Laravel Excel 3.0 is now released and this version mainly focuses on exports and making it as simple as possible and is a complete break from previous versions. Here are some of the highlights from this release:

  • Easily export collections to Excel
  • Export queries with automatic chunking for better performance
  • Queue exports for better performance
  • Easily export Blade views to Excel

To give you an example of exporting in 3.0, take a look at this quick example taken from their documentation.

First, create an InvoicesExport class:

namespace App\Exports;

class InvoicesExport implements FromCollection
    public function collection()
        return Invoice::all();

Next, from your controller initialize the download:

public function export() 
    return Excel::download(new InvoicesExport, 'invoices.xlsx');

Or get fancy and store it to S3:

public function storeExcel() 
    return Excel::store(new InvoicesExport, 'invoices.xlsx', 's3');

Of course, these examples just scratch the surface. Check out the Github repo and official docs for more information.

As mentioned above, v3.0 focuses on exporting and v3.1 will focus on imports, but as of this time, there isn’t a planned release date yet.

This appeared first on Laravel News
Laravel News Partners


Join the weekly newsletter and never miss out on new tips, tutorials, and more.