From cb4c76562da94ffbd0d1f578b89088df08eb8f9d Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Wed, 19 Nov 2025 15:28:27 +0700 Subject: [PATCH] feat: add Classification resource with management pages and migration for classifications table --- .../ClassificationResource.php | 138 ++++++++++++++++++ .../Pages/ManageClassifications.php | 30 ++++ app/Models/Classification.php | 22 +++ app/Models/Master/Classification.php | 10 -- ...24_012236_create_classifications_table.php | 9 +- 5 files changed, 198 insertions(+), 11 deletions(-) create mode 100644 app/Filament/Resources/Master/Classifications/ClassificationResource.php create mode 100644 app/Filament/Resources/Master/Classifications/Pages/ManageClassifications.php create mode 100644 app/Models/Classification.php delete mode 100644 app/Models/Master/Classification.php diff --git a/app/Filament/Resources/Master/Classifications/ClassificationResource.php b/app/Filament/Resources/Master/Classifications/ClassificationResource.php new file mode 100644 index 0000000..f7817ac --- /dev/null +++ b/app/Filament/Resources/Master/Classifications/ClassificationResource.php @@ -0,0 +1,138 @@ +components([ + TextInput::make('name') + ->label('Nama') + ->placeholder('Laporan') + ->autocomplete(false) + ->autofocus() + ->required() + ->maxLength(50), + + RichEditor::make('description') + ->label('Keterangan') + ->placeholder('Silakan isi keterangan klasifikasi di atas') + ->nullable(), + ]) + ->columns(1); + } + + public static function table(Table $table): Table + { + return $table + ->recordTitleAttribute('name') + ->columns([ + TextColumn::make('name') + ->label('Nama') + ->searchable() + ->sortable(), + + ToggleColumn::make('is_active') + ->label('Aktif?') + ->getStateUsing(fn (Classification $record) => $record->is_active === IsActive::ACTIVE) + ->updateStateUsing(function (Classification $record, bool $state) { + $record->is_active = $state ? IsActive::ACTIVE : IsActive::INACTIVE; + $record->save(); + }) + ->sortable(), + + TextColumn::make('created_at') + ->label('Dibuat') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + + TextColumn::make('updated_at') + ->label('Diperbarui') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + + TextColumn::make('deleted_at') + ->label('Dihapus') + ->dateTime() + ->sortable() + ->toggleable(isToggledHiddenByDefault: true), + ]) + ->filters([ + TrashedFilter::make()->native(false), + ]) + ->recordActions([ + EditAction::make()->modalWidth('lg'), + DeleteAction::make(), + ForceDeleteAction::make(), + RestoreAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + DeleteBulkAction::make(), + ForceDeleteBulkAction::make(), + RestoreBulkAction::make(), + ]), + ]) + ->emptyStateIcon('heroicon-o-bookmark') + ->emptyStateDescription('Setelah Anda menulis posting pertama, maka akan muncul disini.') + ->defaultSort('created_at', 'desc') + ->deferFilters(false) + ->reorderable('sort_order'); + } + + public static function getPages(): array + { + return [ + 'index' => ManageClassifications::route('/'), + ]; + } + + public static function getRecordRouteBindingEloquentQuery(): Builder + { + return parent::getRecordRouteBindingEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/Master/Classifications/Pages/ManageClassifications.php b/app/Filament/Resources/Master/Classifications/Pages/ManageClassifications.php new file mode 100644 index 0000000..e7a2ba6 --- /dev/null +++ b/app/Filament/Resources/Master/Classifications/Pages/ManageClassifications.php @@ -0,0 +1,30 @@ +label('Tambah') + ->modalHeading('Tambah Klasifikasi') + ->modalSubmitActionLabel('Simpan') + ->modalCancelActionLabel('Batal') + ->extraModalFooterActions(fn (CreateAction $action): array => [ + $action->makeModalSubmitAction('createAnother', arguments: ['another' => true]) + ->label('Simpan dan Tambah Lagi'), + ]) + ->modalWidth('lg'), + ]; + } +} diff --git a/app/Models/Classification.php b/app/Models/Classification.php new file mode 100644 index 0000000..bbe859f --- /dev/null +++ b/app/Models/Classification.php @@ -0,0 +1,22 @@ + IsActive::class, + 'sort_order' => 'integer', + ]; + } +} diff --git a/app/Models/Master/Classification.php b/app/Models/Master/Classification.php deleted file mode 100644 index fbbdb97..0000000 --- a/app/Models/Master/Classification.php +++ /dev/null @@ -1,10 +0,0 @@ -id(); - $table->timestamps(); + $table->string('name', 50); + $table->text('description')->nullable(); + $table->enum('is_active', [IsActive::values()])->default(IsActive::ACTIVE->value)->comment(IsActive::comment()); + $table->integer('sort_order')->default(0); + $table->timestamp('created_at')->useCurrent(); + $table->timestamp('updated_at')->nullable()->useCurrentOnUpdate(); + $table->softDeletes(); }); }