30
NovFilament Excel is an awesome package that helps you to easily configure your Excel exports in Filament via a bulk or page action.
You can install this package via composer. This will download the package and Laravel Excel. This package
requires PHP 8.0 and Filament 2.0
composer require pxlrbt/filament-excel
For Laravel 9
composer require psr/simple-cache:^2.0 pxlrbt/filament-excel
Starting with v0.2 Filament Excel should work with both filament/filament
and filament/tables
packages. The most simple usage is just adding ExportBulkAction
to your bulk actions.
Example for admin package
<?php
namespace App\Filament\Resources;
use pxlrbt\FilamentExcel\Actions\Tables\ExportBulkAction;
class UserResource extends Resource
{
public static function table(Table $table): Table
{
return $table
->columns([
//
])
->bulkActions([
ExportBulkAction::make()
]);
}
}
Example for table package
<?php
namespace App\Filament\Resources;
use pxlrbt\FilamentExcel\Actions\Tables\ExportBulkAction;
public function getTableBulkActions()
{
return [
ExportBulkAction::make()
];
}
Filament Excel comes with three actions you can use:
Actions\Tables\ExportBulkAction
for table bulk actionsActions\Tables\ExportAction
for table header actionsActions\Pages\ExportAction
for record pagesWithout further configuration, they will try to resolve the fields from the table or form definition and output an Excel file.
You can overwrite the default export class and also configure multiple exports with different settings. The user will be shown a modal to select the export class he wants to use.
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Exports\ExcelExport;
ExportAction::make()->exports([
ExcelExport::make('table')->fromTable(),
ExcelExport::make('form')->fromForm(),
])
Many of the functions for customizing the export class, accept a Closure that gets passed dynamic data:
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Exports\ExcelExport;
ExportAction::make()->exports([
ExcelExport::make('table')->withFilename(fn ($resource) => $resource::getLabel()),
])
The filename is set via ->withFilename()
:
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Exports\ExcelExport;
ExportAction::make()->exports([
// Pass a string
ExcelExport::make()->withFilename(date('Y-m-d') . ' - export'),
// Or pass a Closure
ExcelExport::make()->withFilename(fn ($resource) => $resource::getLabel())
])
You can set the file type via ->withWriterType():
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Exports\ExcelExport;
ExportAction::make()->exports([
ExcelExport::make()->withWriterType(\Maatwebsite\Excel\Excel::XLSX),
])
This package has a lot of features and options wit code examples, For more details, please visit Github.
Published at : 30-11-2022
I am a highly results-driven professional with 12+ years of collective experience in the grounds of web application development especially in laravel, native android application development in java, and desktop application development in the dot net framework. Now managing a team of expert developers at Codebrisk.
Launch project