refactor: Update Excel export setup in Filament resources to use fromTable() method for improved consistency and maintainability

This commit is contained in:
Yoga Pangestu 2026-04-06 10:19:20 +07:00
parent 4f465b17bb
commit 75bd1ad3e6
6 changed files with 78 additions and 76 deletions

View File

@ -16,32 +16,34 @@ public function setUp()
{ {
$this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d')); $this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d'));
$this->withColumns([ $this->fromTable()
Column::make('title') ->except(['index'])
->heading('Judul'), ->withColumns([
Column::make('title')
->heading('Judul'),
Column::make('type') Column::make('type')
->heading('Tipe') ->heading('Tipe')
->formatStateUsing(fn ($state) => $state?->getLabel()), ->formatStateUsing(fn ($state) => $state?->getLabel()),
Column::make('channel') Column::make('channel')
->heading('Kanal') ->heading('Kanal')
->formatStateUsing(fn ($state) => $state->getLabel()), ->formatStateUsing(fn ($state) => $state->getLabel()),
Column::make('social_media') Column::make('social_media')
->heading('Media Sosial') ->heading('Media Sosial')
->formatStateUsing(fn ($state) => $state?->getLabel()), ->formatStateUsing(fn ($state) => $state?->getLabel()),
Column::make('classification.name') Column::make('classification.name')
->heading('Klasifikasi'), ->heading('Klasifikasi'),
Column::make('link') Column::make('link')
->heading('Tautan'), ->heading('Tautan'),
Column::make('posting_date') Column::make('posting_date')
->heading('Tgl Posting') ->heading('Tgl Posting')
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')), ->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
]); ]);
} }
public function headings(): array public function headings(): array

View File

@ -16,37 +16,39 @@ public function setUp()
{ {
$this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d')); $this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d'));
$this->withColumns([ $this->fromTable()
Column::make('mediaMonitoring.title') ->except(['index'])
->heading('Judul Berita'), ->withColumns([
Column::make('mediaMonitoring.title')
->heading('Judul Berita'),
Column::make('issue') Column::make('issue')
->heading('Isu') ->heading('Isu')
->formatStateUsing(fn ($state) => $state?->getLabel()), ->formatStateUsing(fn ($state) => $state?->getLabel()),
Column::make('response') Column::make('response')
->heading('Respon') ->heading('Respon')
->formatStateUsing(fn ($state) => $state?->getLabel()), ->formatStateUsing(fn ($state) => $state?->getLabel()),
Column::make('location.name') Column::make('location.name')
->heading('Lokus'), ->heading('Lokus'),
Column::make('subLocation.name') Column::make('subLocation.name')
->heading('Sublokus'), ->heading('Sublokus'),
Column::make('classification.name') Column::make('classification.name')
->heading('Klasifikasi'), ->heading('Klasifikasi'),
Column::make('subClassification.name') Column::make('subClassification.name')
->heading('Subklasifikasi'), ->heading('Subklasifikasi'),
Column::make('description') Column::make('description')
->heading('Keterangan'), ->heading('Keterangan'),
Column::make('mediaMonitoring.release_date') Column::make('mediaMonitoring.release_date')
->heading('Tgl Rilis') ->heading('Tgl Rilis')
->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')), ->formatStateUsing(fn ($state) => $state?->translatedFormat('l, d F Y')),
]); ]);
} }
public function headings(): array public function headings(): array

View File

@ -2,7 +2,6 @@
namespace App\Filament\Exports; namespace App\Filament\Exports;
use App\Enums\Channel;
use Maatwebsite\Excel\Concerns\WithEvents; use Maatwebsite\Excel\Concerns\WithEvents;
use Maatwebsite\Excel\Concerns\WithStyles; use Maatwebsite\Excel\Concerns\WithStyles;
use Maatwebsite\Excel\Events\AfterSheet; use Maatwebsite\Excel\Events\AfterSheet;
@ -17,42 +16,44 @@ public function setUp()
{ {
$this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d')); $this->withFilename(fn ($resource) => $resource::getModelLabel().'-'.date('Y-m-d'));
$this->withColumns([ $this->fromTable()
Column::make('code') ->except(['index'])
->heading('Kode'), ->withColumns([
Column::make('code')
->heading('Kode'),
Column::make('media_name') Column::make('media_name')
->heading('Nama Media'), ->heading('Nama Media'),
Column::make('title') Column::make('title')
->heading('Judul'), ->heading('Judul'),
Column::make('channel') Column::make('channel')
->heading('Kanal') ->heading('Kanal')
->formatStateUsing(fn ($state) => Channel::tryFrom($state)?->getLabel() ?? $state), ->formatStateUsing(fn ($state) => $state->getLabel() ?? $state),
Column::make('writter') Column::make('writter')
->heading('Penulis'), ->heading('Penulis'),
Column::make('link') Column::make('link')
->heading('Tautan'), ->heading('Tautan'),
Column::make('news_page') Column::make('news_page')
->heading('Halaman Berita'), ->heading('Halaman Berita'),
Column::make('influencer') Column::make('influencer')
->heading('Influencer'), ->heading('Influencer'),
Column::make('keyword') Column::make('keyword')
->heading('Kata Kunci'), ->heading('Kata Kunci'),
Column::make('themes') Column::make('themes')
->heading('Tema') ->heading('Tema')
->getStateUsing(fn ($record) => $record->themes->pluck('name')->join(', ')), ->getStateUsing(fn ($record) => $record->themes->pluck('name')->join(', ')),
Column::make('release_date') Column::make('release_date')
->heading('Tgl Rilis'), ->heading('Tgl Rilis'),
]); ]);
} }
public function headings(): array public function headings(): array

View File

@ -22,8 +22,7 @@ protected function getHeaderActions(): array
ExportAction::make() ExportAction::make()
->exports([ ->exports([
ContentRecapExcelExport::make() ContentRecapExcelExport::make(),
->fromTable(),
]) ])
->color('success') ->color('success')
->icon(null), ->icon(null),

View File

@ -22,8 +22,7 @@ protected function getHeaderActions(): array
ExportAction::make() ExportAction::make()
->exports([ ->exports([
IssueManagementExcelExport::make() IssueManagementExcelExport::make(),
->fromTable(),
]) ])
->color('success') ->color('success')
->icon(null), ->icon(null),

View File

@ -25,8 +25,7 @@ protected function getHeaderActions(): array
ExportAction::make() ExportAction::make()
->exports([ ->exports([
MediaMonitoringExcelExport::make() MediaMonitoringExcelExport::make(),
->fromTable(),
]) ])
->color('success') ->color('success')
->icon(null), ->icon(null),