F
Filament5d ago
iyaa

Export Action didn't Export A Defined Column

Im trying to export a table of temporary password into xlsx & csv. The migration and model is pretty simple model
class TemporaryPassword extends Model
{
use HasFactory;

protected $fillable = ['nis', 'plaintext_password'];
}
class TemporaryPassword extends Model
{
use HasFactory;

protected $fillable = ['nis', 'plaintext_password'];
}
and here's the exporter class
<?php

namespace App\Filament\Exports;

use App\Models\TemporaryPassword;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
use OpenSpout\Common\Entity\Style\CellAlignment;
use OpenSpout\Common\Entity\Style\CellVerticalAlignment;
use OpenSpout\Common\Entity\Style\Color;
use OpenSpout\Common\Entity\Style\Style;

class TemporaryPasswordExporter extends Exporter
{
protected static ?string $model = TemporaryPassword::class;

public static function getColumns(): array
{
return [
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('nis')
->label('NIS'),
ExportColumn::make('plaintext_password')
->formatStateUsing(fn($record) => $record->plaintext),
];
}

public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your temporary password 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\TemporaryPassword;
use Filament\Actions\Exports\ExportColumn;
use Filament\Actions\Exports\Exporter;
use Filament\Actions\Exports\Models\Export;
use OpenSpout\Common\Entity\Style\CellAlignment;
use OpenSpout\Common\Entity\Style\CellVerticalAlignment;
use OpenSpout\Common\Entity\Style\Color;
use OpenSpout\Common\Entity\Style\Style;

class TemporaryPasswordExporter extends Exporter
{
protected static ?string $model = TemporaryPassword::class;

public static function getColumns(): array
{
return [
ExportColumn::make('id')
->label('ID'),
ExportColumn::make('nis')
->label('NIS'),
ExportColumn::make('plaintext_password')
->formatStateUsing(fn($record) => $record->plaintext),
];
}

public static function getCompletedNotificationBody(Export $export): string
{
$body = 'Your temporary password 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;
}
}
When I try to export, the field ID and nis exported to the xlsx & csv, but the plaintext_password didnt. I already tried to add protected $hidden = []; on the model yet it didnt work
0 Replies
No replies yetBe the first to reply to this messageJoin

Did you find this page helpful?