Two months ago we released a first version of Laravel Nova Excel that exports Nova resources to Excel. At Maatwebsite we still love Laravel Nova and couldn’t wait to extend our package even more!
Our main focus on this release was to try and get the data you see in the resource index screen to be exactly the same in the export. This meant we needed to redesign some of the internals that made the translation from Resources to our Laravel Excel library.
User resource index screen
Exported users
In our opinion the most valuable addition is the possibility to export relation values. All BelongsTo relations added to the Resources fields will now be displayed in the same way as on the index screen.
BelongsTo::make('User'),
Alternatively you can also eager-load the relation and access its data.
public static $with = ['user'];
public function fields(Request $request)
{
return [
Text::make('User Name', 'user.name'),
];
}
Another new addition is the possibility to export computed fields. They will be displayed just the same as in your index view.
Text::make('Random number', function () {
return str_random();
}),
Laravel Nova Excel 1.1 now also calls display callbacks. All changes you have made to display the field in the index view will now also be respected when exporting.
Text::make('Name')
->displayUsing(function ($value) {
return strtoupper($value);
})
We also took the time to improve the integration with lenses. Lenses will now also be exported with the same features as described above!
When using ->withHeading()
on the export action, it will now use the Field name instead of the attribute name. It’s still possible to override the heading row by passing the values in the ->withHeadings(['heading-1'])
method.
(new DownloadExcel())->withHeadings(),
You can read more about Laravel Nova Excel in our dedicated documentation: https://laravel-excel.maatwebsite.nl/nova/1.1/getting-started/
Originally posted at: https://medium.com/maatwebsite/laravel-nova-excel-1-1-ready-for-launch-37e0ff1aef06
I work at Maatwebsite on weekdays and I am a passionate filmmaker in my free time. Find me on Twitter & Github.