Custom Exporter Colum

Hello everyone, I've created a page that displays a table with a fairly complex layout and successfully implemented it. However, I'm encountering an issue when trying to implement the exporter, and I'm getting the error:
Undefined array key "label"
Undefined array key "label"
Could anyone provide a solution or help me identify where the mistake might be?
No description
No description
No description
7 Replies
christmex
christmex3w ago
Where is ur export code?
Dennis Koch
Dennis Koch3w ago
How should we help if all you provide is 3 screenshots without even knowing what you are doing? Share some code and share the Flare exception (share button on exception page)
Jr.Pikong
Jr.Pikong2w ago
my apologies for the lack of clarity on my question, there my code TransactionAggreGateExporter.php :
<?php

namespace App\Filament\Exports;

use App\Models\TransactionSummaryAgg;
use App\Models\TrxAggreGate;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class TransactionAggreGateExporter extends Exporter
{
protected static ?string $model = TrxAggreGate::class;

public static function getColumns(): array
{
// Fetch distinct denominations
$denominations = TransactionSummaryAgg::select('denom')
->distinct()
->pluck('denom');

// Define columns
$columns = [
ExportColumn::make('trx_date')
];

foreach ($denominations as $denom) {
$columns[] = ExportColumn::make($denom);
$columns[] = ExportColumn::make("Total_Value_{$denom}");
}
return $columns;
}

public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your trx aggre gate export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';

if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}

return $body;
}
}
<?php

namespace App\Filament\Exports;

use App\Models\TransactionSummaryAgg;
use App\Models\TrxAggreGate;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Relations\MorphTo;

class TransactionAggreGateExporter extends Exporter
{
protected static ?string $model = TrxAggreGate::class;

public static function getColumns(): array
{
// Fetch distinct denominations
$denominations = TransactionSummaryAgg::select('denom')
->distinct()
->pluck('denom');

// Define columns
$columns = [
ExportColumn::make('trx_date')
];

foreach ($denominations as $denom) {
$columns[] = ExportColumn::make($denom);
$columns[] = ExportColumn::make("Total_Value_{$denom}");
}
return $columns;
}

public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your trx aggre gate export has completed and ' . number_format($export->successful_rows) . ' ' . str('row')->plural($export->successful_rows) . ' exported.';

if ($failedRowsCount = $export->getFailedRowsCount()) {
$body .= ' ' . number_format($failedRowsCount) . ' ' . str('row')->plural($failedRowsCount) . ' failed to export.';
}

return $body;
}
}
In resource I call with this action :
return $table
->headerActions([
ExportAction::make()
->exporter(TransactionAggreGateExporter::class)
->icon('heroicon-o-arrow-down-tray')
->color('primary')
->chunkSize(2000)
->formats([
ExportFormat::Xlsx,
])
->label('Export')
->fileName('SummaryReport'.now())
])
return $table
->headerActions([
ExportAction::make()
->exporter(TransactionAggreGateExporter::class)
->icon('heroicon-o-arrow-down-tray')
->color('primary')
->chunkSize(2000)
->formats([
ExportFormat::Xlsx,
])
->label('Export')
->fileName('SummaryReport'.now())
])
Jr.Pikong
Jr.Pikong2w ago
in laravel.log I get error :
[2024-06-19 16:20:34] local.ERROR: Undefined array key "label" {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined array key \"label\" at /var/www/html/vendor/filament/actions/src/Concerns/CanExportRecords.php:155)
[stacktrace]
[2024-06-19 16:20:34] local.ERROR: Undefined array key "label" {"userId":1,"exception":"[object] (ErrorException(code: 0): Undefined array key \"label\" at /var/www/html/vendor/filament/actions/src/Concerns/CanExportRecords.php:155)
[stacktrace]
Jr.Pikong
Jr.Pikong2w ago
@Dennis Koch this is my detail log error: https://flareapp.io/share/353gO6W5
Flare
Undefined array key "label" - The error occurred at http://localhost/admin/transaction-agree-gate
Dennis Koch
Dennis Koch2w ago
To me it sounds like you include a db column that doesn’t exist from your dynamic export script?