From 557ae954d26de536a61519b266ffc264826dbbc6 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Wed, 18 Feb 2026 22:41:49 +0700 Subject: [PATCH] feat: Implement Customer management with resource, pages, model, and migration for customer data handling --- .../Master/Customers/CustomerResource.php | 131 ++++++++++++++++++ .../Customers/Pages/ManageCustomers.php | 31 +++++ app/Models/Customer.php | 14 ++ ...26_02_18_000003_create_customers_table.php | 32 +++++ 4 files changed, 208 insertions(+) create mode 100644 app/Filament/Resources/Master/Customers/CustomerResource.php create mode 100644 app/Filament/Resources/Master/Customers/Pages/ManageCustomers.php create mode 100644 app/Models/Customer.php create mode 100644 database/migrations/2026_02_18_000003_create_customers_table.php diff --git a/app/Filament/Resources/Master/Customers/CustomerResource.php b/app/Filament/Resources/Master/Customers/CustomerResource.php new file mode 100644 index 0000000..07edfc8 --- /dev/null +++ b/app/Filament/Resources/Master/Customers/CustomerResource.php @@ -0,0 +1,131 @@ +components([ + TextInput::make('name') + ->label('Nama') + ->placeholder('John Doe') + ->required() + ->maxLength(100) + ->autofocus() + ->autocomplete(false), + + TextInput::make('phone_number') + ->label('Nomor HP') + ->placeholder('08xxxxxxxxxx') + ->required() + ->maxLength(20) + ->autocomplete(false), + + TextInput::make('address') + ->label('Alamat') + ->placeholder('Jl. Raya No. 123, Jakarta Selatan') + ->maxLength(255) + ->autocomplete(false), + ]) + ->columns(1); + } + + public static function table(Table $table): Table + { + return $table + ->columns([ + TextColumn::make('name') + ->label('Nama') + ->searchable() + ->sortable(), + + TextColumn::make('phone_number') + ->label('Nomor HP') + ->searchable() + ->sortable(), + + TextColumn::make('address') + ->label('Alamat') + ->limit(40) + ->toggleable(isToggledHiddenByDefault: true), + + ...TimestampColumns::make(), + ]) + ->filters([ + TrashedFilter::make() + ->native(false), + ]) + ->recordActions([ + EditAction::make() + ->modalWidth(Width::Large), + + DeleteAction::make(), + + ForceDeleteAction::make(), + + RestoreAction::make(), + ]) + ->toolbarActions([ + BulkActionGroup::make([ + ...DefaultBulkActions::make('Pelanggan'), + ]), + ]) + ->emptyStateIcon(Heroicon::UserPlus) + ->emptyStateDescription('Setelah Anda membuat data pertama, maka akan muncul disini.') + ->defaultSort('created_at', 'desc') + ->deferFilters(false); + } + + public static function getPages(): array + { + return [ + 'index' => ManageCustomers::route('/'), + ]; + } + + public static function getRecordRouteBindingEloquentQuery(): Builder + { + return parent::getRecordRouteBindingEloquentQuery() + ->withoutGlobalScopes([ + SoftDeletingScope::class, + ]); + } +} diff --git a/app/Filament/Resources/Master/Customers/Pages/ManageCustomers.php b/app/Filament/Resources/Master/Customers/Pages/ManageCustomers.php new file mode 100644 index 0000000..ab7bc72 --- /dev/null +++ b/app/Filament/Resources/Master/Customers/Pages/ManageCustomers.php @@ -0,0 +1,31 @@ +label('Tambah') + ->modalHeading('Tambah Pelanggan') + ->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/Models/Customer.php b/app/Models/Customer.php new file mode 100644 index 0000000..dc25f70 --- /dev/null +++ b/app/Models/Customer.php @@ -0,0 +1,14 @@ +id(); + $table->string('name', 100); + $table->string('phone_number', 20); + $table->string('address')->nullable(); + $table->timestamp('created_at')->useCurrent(); + $table->timestamp('updated_at')->nullable()->useCurrentOnUpdate(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('customers'); + } +};