Export Column State Not Working

Hi guys, I have a boolean column in a relationship model and I want to personalize it so true means yes and false means no, however it's not customizing by state on the Exporter class. I'm getting 1 or 0 with or without state, is this a bug or am I doing something wrong? public static function getColumns(): array { return [ ExportColumn::make('docto.obrigatorio') ->label('Obrigatório') ->state(function (EmpresaDocto $record) { if ($record->docto->obrigatorio === 1) { return 'Sim'; } return 'Não'; }), ]; }
Solution:
->formatStateUsing(fn ($state): string => $state === 1 ? 'Sim' : 'Não')
->formatStateUsing(fn ($state): string => $state === 1 ? 'Sim' : 'Não')
...
Jump to solution
12 Replies
Solution
LeandroFerreira
LeandroFerreira6mo ago
->formatStateUsing(fn ($state): string => $state === 1 ? 'Sim' : 'Não')
->formatStateUsing(fn ($state): string => $state === 1 ? 'Sim' : 'Não')
Renan Pereira
Renan PereiraOP6mo ago
Tried this and still doesn't work. I've also tried to format the created_at column of the main model to see if it's a relationship problem but it doesn't work either.
LeandroFerreira
LeandroFerreira6mo ago
could you share the whole code?
Renan Pereira
Renan PereiraOP6mo ago
Yeah, sure. Here it is: <?php namespace App\Filament\Exports; use App\Models\EmpresaDocto; use Filament\Actions\Exports\ExportColumn; use Filament\Actions\Exports\Exporter; use Filament\Actions\Exports\Models\Export; class EmpresaDoctoExporter extends Exporter { protected static ?string $model = EmpresaDocto::class; public static function getColumns(): array { return [ ExportColumn::make('id') ->label('ID'), ExportColumn::make('docto.area') ->label('Área'), ExportColumn::make('docto.sigla') ->label('Sigla'), ExportColumn::make('obra.descricao') ->label('Descrição'), ExportColumn::make('dt_realizacao') ->label('Dt emissão'), ExportColumn::make('dt_competencia') ->label('Dt Competência'), ExportColumn::make('dt_vcto') ->label('Dt Vencimento'), ExportColumn::make('created_at') ->label('Dt Criação') ->formatStateUsing(fn ($state): string => $state->format('d/m/Y')), ExportColumn::make('docto.obrigatorio') ->label('Obrigatório') ->formatStateUsing(fn ($state): string => $state === 1 ? 'Sim' : 'Não'), ]; } public static function getCompletedNotificationBody(Export $export): string { $body = 'Your empresa docto 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; } }
LeandroFerreira
LeandroFerreira6mo ago
try $state == 1
Renan Pereira
Renan PereiraOP6mo ago
Didn't work, still getting 1 and 0s
LeandroFerreira
LeandroFerreira6mo ago
let me try..
Renan Pereira
Renan PereiraOP6mo ago
These are the versions I'm using (Laravel 10.48.12):
- Upgrading filament/actions (v3.2.81 => v3.2.86): Extracting archive - Upgrading filament/notifications (v3.2.81 => v3.2.86): Extracting archive - Upgrading filament/infolists (v3.2.81 => v3.2.86): Extracting archive - Upgrading filament/forms (v3.2.81 => v3.2.86): Extracting archive - Upgrading filament/tables (v3.2.81 => v3.2.86): Extracting archive
LeandroFerreira
LeandroFerreira6mo ago
same version, this is working here are you using ExportAction in the table, headerActions? are you using queue? if you are using QUEUE_CONNECTION <> sync, you should restart the queue after changing the export..
Renan Pereira
Renan PereiraOP6mo ago
I tried on both, ExportAction and ExportBulkAction, none where working ->headerActions([ Action::make('create') ->label('Adicionar') ->icon('heroicon-c-plus') ->color('success') ->hidden(!\Auth::user()->can('add_new_docto_empresa')) ->extraAttributes([ 'class' => 'p-2 bg-success text-white text-lg', ]) ->url(fn (): string => route('empresas.doctos.create', $this->empresa->id)), ExportAction::make() ->exporter(EmpresaDoctoExporter::class) ->label('Exportar') ->color('info') ->icon('heroicon-s-arrow-down-tray') ]) ->bulkActions([ ExportBulkAction::make() ->exporter(EmpresaDoctoExporter::class) ->label('Exportar') ->color('info') ->icon('heroicon-s-arrow-down-tray') Yes, this worked. I'm using database. Thank you so much!
LeandroFerreira
LeandroFerreira6mo ago
you need to restart when you change it..
Renan Pereira
Renan PereiraOP6mo ago
I did not know this... been searching for a Filament problem but was a Laravel issue. Thanks again !!
Want results from more Discord servers?
Add your server