diff --git a/app/Filament/Resources/Master/Classifications/ClassificationResource.php b/app/Filament/Resources/Master/Classifications/ClassificationResource.php index f7817ac..01b279f 100644 --- a/app/Filament/Resources/Master/Classifications/ClassificationResource.php +++ b/app/Filament/Resources/Master/Classifications/ClassificationResource.php @@ -47,7 +47,7 @@ public static function form(Schema $schema): Schema ->components([ TextInput::make('name') ->label('Nama') - ->placeholder('Laporan') + ->placeholder('Pelaporan') ->autocomplete(false) ->autofocus() ->required() diff --git a/app/Filament/Resources/Master/SubClassifications/Pages/ManageSubClassifications.php b/app/Filament/Resources/Master/SubClassifications/Pages/ManageSubClassifications.php new file mode 100644 index 0000000..12ff9dc --- /dev/null +++ b/app/Filament/Resources/Master/SubClassifications/Pages/ManageSubClassifications.php @@ -0,0 +1,30 @@ +label('Tambah') + ->modalHeading('Tambah Sub 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/Filament/Resources/Master/SubClassifications/SubClassificationResource.php b/app/Filament/Resources/Master/SubClassifications/SubClassificationResource.php new file mode 100644 index 0000000..26f8137 --- /dev/null +++ b/app/Filament/Resources/Master/SubClassifications/SubClassificationResource.php @@ -0,0 +1,153 @@ +components([ + Select::make('classification_id') + ->label('Klasifikasi') + ->options(Classification::query()->pluck('name', 'id')) + ->searchable() + ->native(false) + ->required() + ->rules(['exists:classifications,id']), + + TextInput::make('name') + ->label('Nama') + ->placeholder('Pengaduan') + ->autocomplete(false) + ->autofocus() + ->required() + ->maxLength(50), + + RichEditor::make('description') + ->label('Keterangan') + ->placeholder('Silakan isi keterangan sub klasifikasi di atas') + ->nullable(), + ]) + ->columns(1); + } + + public static function table(Table $table): Table + { + return $table + ->recordTitleAttribute('name') + ->columns([ + TextColumn::make('classification.name') + ->label('Klasifikasi') + ->searchable() + ->sortable(), + + TextColumn::make('name') + ->label('Nama') + ->searchable() + ->sortable(), + + ToggleColumn::make('is_active') + ->label('Aktif?') + ->getStateUsing(fn (SubClassification $record) => $record->is_active === IsActive::ACTIVE) + ->updateStateUsing(function (SubClassification $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' => ManageSubClassifications::route('/'), + ]; + } + + public static function getRecordRouteBindingEloquentQuery(): Builder + { + return parent::getRecordRouteBindingEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Models/Classification.php b/app/Models/Classification.php index bbe859f..4d4f431 100644 --- a/app/Models/Classification.php +++ b/app/Models/Classification.php @@ -4,6 +4,7 @@ use App\Enums\IsActive; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\SoftDeletes; class Classification extends Model @@ -19,4 +20,9 @@ protected function casts(): array 'sort_order' => 'integer', ]; } + + public function subClassifications(): HasMany + { + return $this->hasMany(SubClassification::class); + } } diff --git a/app/Models/SubClassification.php b/app/Models/SubClassification.php new file mode 100644 index 0000000..719409e --- /dev/null +++ b/app/Models/SubClassification.php @@ -0,0 +1,28 @@ + IsActive::class, + 'sort_order' => 'integer', + ]; + } + + public function classification(): BelongsTo + { + return $this->belongsTo(Classification::class); + } +} diff --git a/database/migrations/2025_11_19_082630_create_sub_classifications_table.php b/database/migrations/2025_11_19_082630_create_sub_classifications_table.php new file mode 100644 index 0000000..1c48adb --- /dev/null +++ b/database/migrations/2025_11_19_082630_create_sub_classifications_table.php @@ -0,0 +1,35 @@ +id(); + $table->foreignId('classification_id')->constrained()->cascadeOnDelete(); + $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(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('sub_classifications'); + } +};