Installation Add the package via Composer:
composer require pxlrbt/filament-excel
Publish the config (if needed):
php artisan vendor:publish --provider="Pxlrbt\FilamentExcel\FilamentExcelServiceProvider" --tag="filament-excel-config"
Basic Setup
Register the package in app/Providers/Filament/AdminPanelProvider.php:
public function panel(Panel $panel): Panel
{
return $panel
->plugins([
\Pxlrbt\FilamentExcel\FilamentExcelPlugin::make(),
]);
}
First Export
Use the exportTable method in a Filament Resource:
use Pxlrbt\FilamentExcel\Actions\ExportTable;
public static function table(Table $table): Table
{
return $table
->columns([...])
->actions([
ExportTable::make(),
]);
}
config/filament-excel.php (default settings, file naming, storage paths).Pxlrbt\FilamentExcel\Actions namespace for reusable export actions.Export a filtered table as an Excel file with a single click:
use Pxlrbt\FilamentExcel\Actions\ExportTable;
public static function table(Table $table): Table
{
return $table
->columns([...])
->actions([
ExportTable::make()
->filename('users-export-' . now()->format('Y-m-d'))
->withHeadings()
->withEvents(), // Optional: trigger events before/after export
]);
}
Dynamic Filename Generation Use closures for dynamic filenames:
ExportTable::make()
->filename(fn () => "reports/{$this->getKey()}-export.xlsx")
Customizing Exported Data
Override the getExportedTableData method in your Resource:
public function getExportedTableData(): array
{
return $this->table->getRecords()->map(fn ($record) => [
'name' => $record->name,
'custom_field' => $record->custom_field ?? 'N/A',
]);
}
Batch Exports
Combine with Filament’s BulkAction:
use Filament\Actions\Action;
use Pxlrbt\FilamentExcel\Actions\ExportTable;
public static function table(Table $table): Table
{
return $table
->actions([
Action::make('export-selected')
->action(ExportTable::make()
->onlySelected()
),
]);
}
Event-Based Extensions
Listen to filament-excel.exporting or filament-excel.exported events:
// In a service provider
Excel::exporting(function (Exporting $event) {
$event->setFilename('custom-prefix-' . $event->filename);
});
Filament Forms: Use ExportTable in form actions for custom exports:
public static function form(Form $form): Form
{
return $form
->actions([
Action::make('export-form-data')
->action(ExportTable::make()
->withFormData($form->getState())
),
]);
}
Laravel Excel Integration
Leverage Maatwebsite\Excel features (e.g., WithHeadings, WithEvents) via the package’s config:
// config/filament-excel.php
'excel' => [
'with_headings' => true,
'events' => [
'before' => \App\Listeners\LogExport::class,
],
],
API Routes Expose exports via API:
Route::get('/export', function () {
return Excel::download(
new UsersExport,
'users.xlsx'
);
});
Filament Version Mismatch
composer.json for compatibility.pxlrbt/filament-excel:dev-main for bleeding-edge Filament 3 support.Large Dataset Performance
getExportedTableData():
public function getExportedTableData(): array
{
return $this->table->getRecords()->chunk(1000)->toArray();
}
Maatwebsite\Excel\Concerns\WithCustomStartCell and WithChunkReading.Stale Data in Exports
getExportedTableData():
public function getExportedTableData(): array
{
return $this->table->getRecords()->fresh()->toArray();
}
File Storage Paths
filament-excel.storage in config and ensure the disk exists:
// config/filament-excel.php
'storage' => 'public',
Run php artisan storage:link if using public disk.Log Export Events Add a listener to debug:
Excel::exporting(function (Exporting $event) {
\Log::info('Exporting:', [
'filename' => $event->filename,
'data' => count($event->data),
]);
});
Check Excel Writer
If exports are corrupted, test with a minimal Maatwebsite\Excel class:
use Maatwebsite\Excel\Concerns\FromCollection;
class TestExport implements FromCollection
{
public function collection()
{
return collect([['test' => 'data']]);
}
}
Excel::download(new TestExport, 'test.xlsx');
Clear Caches After config changes, run:
php artisan optimize:clear
php artisan view:clear
Custom Export Classes
Extend Pxlrbt\FilamentExcel\Actions\ExportTable:
namespace App\Actions;
use Pxlrbt\FilamentExcel\Actions\ExportTable;
class CustomExport extends ExportTable
{
protected function getFilename(): string
{
return 'custom-' . parent::getFilename();
}
}
Modify Excel Writer Bind a custom writer in the service provider:
Excel::extend('custom', function () {
return new \App\Exports\CustomExcelWriter;
});
Add Presets Create reusable export configurations:
// app/Exports/ReportPreset.php
namespace App\Exports;
use Pxlrbt\FilamentExcel\Actions\ExportTable;
class ReportPreset extends ExportTable
{
public static function make(): static
{
return parent::make()
->withHeadings()
->withEvents()
->filename('report-' . now()->format('Y-m-d'));
}
}
Localization
Override labels in resources/lang/en/filament-excel.php:
return [
'export' => [
'title' => 'Download Excel',
'description' => 'Export selected records to Excel',
],
];
storage/app/filament-excel. Change via:
'storage' => 's3', // or any configured disk
:, ?, /) in filenames.memory_limit in php.ini for large exports:
memory_limit = 512M
How can I help you explore Laravel packages today?