From 71ea216b966f8d91fa10c594c7e07a2b706b71ee Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Tue, 17 Feb 2026 19:43:10 +0700 Subject: [PATCH] refactor: Update Feed model and resource to use integer for stock and adjust price formatting --- app/Filament/Resources/Master/Feeds/FeedResource.php | 7 +++---- app/Models/Feed.php | 2 +- .../migrations/2026_02_09_024536_create_feeds_table.php | 2 +- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/app/Filament/Resources/Master/Feeds/FeedResource.php b/app/Filament/Resources/Master/Feeds/FeedResource.php index 95c320d..d1c755b 100644 --- a/app/Filament/Resources/Master/Feeds/FeedResource.php +++ b/app/Filament/Resources/Master/Feeds/FeedResource.php @@ -19,7 +19,6 @@ use Filament\Schemas\Schema; use Filament\Support\Enums\Width; use Filament\Support\Icons\Heroicon; -use Filament\Support\RawJs; use Filament\Tables\Columns\TextColumn; use Filament\Tables\Filters\TrashedFilter; use Filament\Tables\Table; @@ -65,11 +64,11 @@ public static function form(Schema $schema): Schema TextInput::make('price') ->label('Harga') - ->placeholder('1,000,000') + ->placeholder('1.000.000') ->autocomplete(false) ->autofocus() ->required() - ->mask(RawJs::make('$money($input)')) + ->currencyMask(thousandSeparator: '.', decimalSeparator: ',', precision: 0) ->prefix('Rp') ->helperText('Harga per satuan yang dipilih.') ->dehydrateStateUsing(fn ($state) => str_replace(',', '', $state)), @@ -101,7 +100,7 @@ public static function table(Table $table): Table TextColumn::make('stock') ->label('Stok') - ->numeric(decimalPlaces: 2) + ->numeric(decimalPlaces: 0) ->suffix(fn (Feed $record) => ' '.$record->unit->alias) ->sortable(), diff --git a/app/Models/Feed.php b/app/Models/Feed.php index f14d4b6..6612a76 100644 --- a/app/Models/Feed.php +++ b/app/Models/Feed.php @@ -19,7 +19,7 @@ class Feed extends Model implements HasMedia protected function casts(): array { return [ - 'stock' => 'decimal:2', + 'stock' => 'integer', 'price' => 'integer', ]; } diff --git a/database/migrations/2026_02_09_024536_create_feeds_table.php b/database/migrations/2026_02_09_024536_create_feeds_table.php index 8488eb8..7e71dd4 100644 --- a/database/migrations/2026_02_09_024536_create_feeds_table.php +++ b/database/migrations/2026_02_09_024536_create_feeds_table.php @@ -15,7 +15,7 @@ public function up(): void $table->id(); $table->string('name', 50); $table->foreignId('unit_id')->constrained()->cascadeOnDelete(); - $table->decimal('stock', 15, 2)->default(0); + $table->unsignedInteger('stock')->default(0); $table->unsignedInteger('price'); $table->timestamp('created_at')->useCurrent(); $table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();