New milestone: 20 million downloads for Laravel Excel

Patrick Brouwers
Spartner
Published in
4 min readJul 22, 2020

Not too long ago we celebrated the 10th million download of Laravel Excel and today it’s time to celebrate a new milestone! Laravel Excel has reached 20 million downloads!

We are happy to have reached this milestone and thank you all for using our package over the last 6,5 years! Cheers to many more imports and exports!

Laravel Excel 3.1.20

In other news, we have released Laravel Excel 3.1.20 with some improvements for running imports on Vapor and working with row numbers, along with some fixes and changes. You can find a write up about this new release here.

New features

Re-sycing remote temporary file

When dealing with a multi server setup (and thus using a remote temporary file), it’s possible for the clean up that occurs after entire queue has been run to only cleanup the server that the last AfterImportJob runs on. The rest of the server would still have the local temporary file stored on it. In this case your local storage limits can be exceeded and future imports won’t be processed (This is especially an issue with Vapor).

To mitigate this you can set the new config settings (force_resync_remote) to true. After every queued chunk the local temporary file will be deleted on the server that processed it. Without this setting it will only happen at the end of the process.

Remember row number

A new trait was added that helps keeping track of the current row number. This can be especially useful when dealing with the ToModel concern. You can get the current row number by using the `$this->rowNumber` property.

new UsersExport implements ToModel
{
use RemembersRowNumber;
public function model(array $row)
{
// You can use the current row number.
$this->rowNumber;
}
}

Remember chunk offset

In additional to the row number trait also a chunk offset trait was added. It keeps track of the start row of the current chunk. This can be especially helpful when dealing with Chunked Imports.

new UsersExport implements ToModel, WithChunkReading
{
use RemembersChunkOffset;
public function model(array $row)
{
// You can get the current chunk offset
$this->getChunkOffset();
}

public function chunkSize(): int
{
return 50;
}
}

WithColumnLimit concern

Another addition is the WithColumnFilter concern, it allows to specify an end column. This can be useful if you only want to read a very specific range of columns.

new UsersImport implements ToModel, WithColumnLimit
{
public function model(array $row)
{
// $row will only contain 2 columns (A & B)
}

public function endColumn(): string
{
return 'B';
}
}

WithReadFilter concern

Behind the scenes read filters are used for chunk reading and the row limit concern. In some cases you might want to filter or skip rows yourself. You can do now by implementing the WithReadFilter concern.

class CustomFilter implements IReadFilter
{
public function readCell($column, $row, $worksheetName = '')
{
return $row < 10;
}
}

In your export:

new UsersExport implements WithReadFilter
{
public function readFilter(): IReadFilter
{
return new CustomFilter();
}
}

Publishing the stubs

It’s now possible to publish the stubs that are used when using the php artisan make:import and php artisan make:export commands so you can change them to your liking.

php artisan stub:publish (Laravel 7.x)

Changes

Interacting with queued jobs

The InteractsWithQueue trait was added to the ReadChunk job. The trait allows for the job to be released back onto the queue, useful for instance if using it with the funnel or throttle methods on the Redis facade.

Retry until and middleware on queued imports

It’s possible to specify a retry until method and add middleware to the import:

class UsersExport implements ShouldQueue
{
public function retryUntil()
{
return now()->addSeconds(5);
}

public function middleware()
{
return [
new RateLimited,
];
}
}

More about job middleware can be found in the Laravel documentation: https://laravel.com/docs/7.x/queues#job-middleware

Using WithValidation with FromCollection & FromArray

This release also added support for combining those concerns and works in a similar fashion as for Model imports.

Read filters for WithLimit and HeadingRowImport

WithLimit concern and HeadingRowImport now use read filter, which means it will now only read the necessary rows.

Bump of minimum version PhpSpreadsheet

The minimum version of PhpSpreadsheet was bumped to 1.14.

Fixes

A few things were fixed in this release:

  • Fixed test helper docblocks on the Excel facade.
  • Fix for importing with a start row beyond the highest row.
  • Fixed `BeforeSheet` and `AfterSheet` events receiving exportable instance instead of importable when calling on an Import.
  • Fix for value binders not working in queued exports.
  • Fix when using WithLimit concern when having less rows than the limit.
  • Fix AfterImport job being fired twice if not using queueing.
  • Raw() method now also available on Exportable.
  • Fix for breaking changes in PhpSpreadsheet with empty enclosures.

See the full changelog here: https://github.com/Maatwebsite/Laravel-Excel/blob/3.1/CHANGELOG.md#3120---2020-07-22

Read more about the package at: https://laravel-excel.com/

Don’t forget to send us a postcard of your hometown if you use Laravel Excel. We love to receive them!

Maatwebsite
Markt 2
6231 LS Meerssen
The Netherlands

Do you need help with integrating Laravel 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.

--

--

Patrick Brouwers
Spartner

Loves building awesome things in Laravel, VueJS and TailwindCss. Working @ Spartner. Maintainer of Laravel Excel.