60 lines
2.5 KiB
PHP
60 lines
2.5 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Resources\MyPosts\Tables;
|
|
|
|
use Filament\Actions\Action;
|
|
use Filament\Actions\BulkActionGroup;
|
|
use Filament\Actions\DeleteBulkAction;
|
|
use Filament\Actions\EditAction;
|
|
use Filament\Tables\Columns\TextColumn;
|
|
use Filament\Tables\Table;
|
|
|
|
class MyPostsTable
|
|
{
|
|
public static function configure(Table $table): Table
|
|
{
|
|
return $table
|
|
->columns([
|
|
TextColumn::make('title')->label('Judul')->searchable()->sortable(),
|
|
TextColumn::make('category')->label('Kategori')->badge(),
|
|
TextColumn::make('status')->badge()
|
|
->color(fn ($state) => match ($state) {
|
|
'published' => 'success',
|
|
'pending' => 'warning',
|
|
'rejected' => 'danger',
|
|
default => 'gray',
|
|
}),
|
|
TextColumn::make('rejection_reason')->label('Alasan Penolakan')
|
|
->visible(fn ($record) => $record?->status === 'rejected')
|
|
->limit(40)->default('-'),
|
|
TextColumn::make('created_at')->label('Dibuat')->date('d M Y')->sortable(),
|
|
])
|
|
->recordActions([
|
|
// Hanya bisa edit jika masih draft atau rejected
|
|
EditAction::make()
|
|
->visible(fn ($record) => in_array($record->status, ['draft', 'rejected'])),
|
|
// Ajukan untuk review
|
|
Action::make('submit')
|
|
->label('Ajukan')
|
|
->icon('heroicon-o-paper-airplane')
|
|
->color('info')
|
|
->requiresConfirmation()
|
|
->visible(fn ($record) => in_array($record->status, ['draft', 'rejected']))
|
|
->action(fn ($record) => $record->update(['status' => 'pending', 'rejection_reason' => null])),
|
|
])
|
|
->toolbarActions([
|
|
BulkActionGroup::make([
|
|
DeleteBulkAction::make()
|
|
->before(function ($records) {
|
|
// Tidak bisa hapus yang sudah published
|
|
$records->each(function ($record) {
|
|
if ($record->status === 'published') {
|
|
throw new \Exception("Artikel yang sudah diterbitkan tidak dapat dihapus.");
|
|
}
|
|
});
|
|
}),
|
|
]),
|
|
]);
|
|
}
|
|
}
|