Closed ceesvanegmond closed 6 months ago
I already got an solution :-)
<?php
namespace App\Helpers;
use Illuminate\Database\Eloquent\Model;
use pxlrbt\FilamentExcel\Actions\Tables\ExportAction;
use pxlrbt\FilamentExcel\Columns\Column;
use pxlrbt\FilamentExcel\Exports\ExcelExport;
class ExportHelper
{
public static function exportBooleansToStrings(Model $model): ExportAction
{
return ExportAction::make()->exports([ExcelExport::make('form')
->withColumns(function () use ($model) {
return collect($model->getCasts())
->filter(fn ($type) => $type === 'boolean')
->map(fn ($item, $key) => Column::make($key)->formatStateUsing(fn ($state) => $state ? 'Yes' : 'No'));
})
->fromForm()]);
}
}
Having a bunch of fields which are boolean fields. Using this package; what is the best (or easiest) way to convert those 0 and 1's to 'No' and 'Yes' in the export? Should be that difficult? Should I use a custom formatter?
Right now when using this:
The excel gets filled it 0 and 1 instead of Yes/No