From 4e21468348d781455636763ed3f7cc081c2dfcb1 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Mon, 9 Feb 2026 10:20:39 +0700 Subject: [PATCH] feat: Add unit entity with model, migration, and Filament resource --- .../Master/Units/Pages/ManageUnits.php | 31 +++++ .../Resources/Master/Units/UnitResource.php | 120 ++++++++++++++++++ app/Models/Unit.php | 13 ++ .../2026_02_09_024000_create_units_table.php | 31 +++++ 4 files changed, 195 insertions(+) create mode 100644 app/Filament/Resources/Master/Units/Pages/ManageUnits.php create mode 100644 app/Filament/Resources/Master/Units/UnitResource.php create mode 100644 app/Models/Unit.php create mode 100644 database/migrations/2026_02_09_024000_create_units_table.php diff --git a/app/Filament/Resources/Master/Units/Pages/ManageUnits.php b/app/Filament/Resources/Master/Units/Pages/ManageUnits.php new file mode 100644 index 0000000..99f2160 --- /dev/null +++ b/app/Filament/Resources/Master/Units/Pages/ManageUnits.php @@ -0,0 +1,31 @@ +label('Tambah') + ->modalHeading('Tambah Satuan') + ->modalSubmitActionLabel('Simpan') + ->modalCancelActionLabel('Batal') + ->extraModalFooterActions(fn (CreateAction $action): array => [ + $action->makeModalSubmitAction('createAnother', arguments: ['another' => true]) + ->label('Simpan dan Tambah Lagi'), + ]) + ->modalWidth(Width::Large), + ]; + } +} diff --git a/app/Filament/Resources/Master/Units/UnitResource.php b/app/Filament/Resources/Master/Units/UnitResource.php new file mode 100644 index 0000000..c773817 --- /dev/null +++ b/app/Filament/Resources/Master/Units/UnitResource.php @@ -0,0 +1,120 @@ +components([ + TextInput::make('name') + ->label('Nama') + ->placeholder('Kilogram') + ->required() + ->maxLength(50) + ->autofocus() + ->autocomplete(false), + + TextInput::make('alias') + ->label('Alias') + ->placeholder('Kg') + ->required() + ->maxLength(20) + ->autocomplete(false), + ]) + ->columns(1); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('name') + ->label('Nama') + ->searchable() + ->sortable(), + + TextColumn::make('alias') + ->label('Alias') + ->searchable() + ->sortable(), + + ...TimestampColumns::make(), + ]) + ->filters([ + TrashedFilter::make() + ->native(false), + ]) + ->recordActions([ + EditAction::make() + ->modalWidth(Width::Large), + + DeleteAction::make(), + + ForceDeleteAction::make(), + + RestoreAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + ...DefaultBulkActions::make('Satuan'), + ]), + ]) + ->emptyStateIcon(Heroicon::Scale) + ->emptyStateDescription('Setelah Anda membuat data pertama, maka akan muncul disini.') + ->defaultSort('created_at', 'desc') + ->deferFilters(false); + } + + public static function getPages(): array + { + return [ + 'index' => ManageUnits::route('/'), + ]; + } + + public static function getRecordRouteBindingEloquentQuery(): Builder + { + return parent::getRecordRouteBindingEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Models/Unit.php b/app/Models/Unit.php new file mode 100644 index 0000000..b357b44 --- /dev/null +++ b/app/Models/Unit.php @@ -0,0 +1,13 @@ +id(); + $table->string('name', 50); + $table->string('alias', 20); + $table->timestamp('created_at')->useCurrent(); + $table->timestamp('updated_at')->nullable()->useCurrentOnUpdate(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('units'); + } +};