loadCartFromDb(); } #[On('cart-updated')] public function onCartUpdated(): void { $this->syncTotalPriceFromCart(); } protected function syncTotalPriceFromCart(): void { $total = (int) FeedPurchaseItem::whereNull('feed_purchase_id')->sum('subtotal'); $this->form->fill([ ...$this->form->getState(), 'total_price' => $total, ]); } protected function getHeaderActions(): array { return [ BackAction::make() ->url(ListFeedPurchases::getUrl()), ]; } protected function getRedirectUrl(): string { return $this->getResource()::getUrl('index'); } protected function mutateFormDataBeforeCreate(array $data): array { $total = FeedPurchaseItem::whereNull('feed_purchase_id')->sum('subtotal'); $data['total_price'] = $total; return $data; } protected function afterCreate(): void { FeedPurchaseItem::whereNull('feed_purchase_id') ->update(['feed_purchase_id' => $this->record->id]); $this->record->updateFeedStock(); } protected function getCreatedNotification(): ?Notification { return Notification::make() ->title('Data Berhasil Disimpan') ->body('Data baru telah berhasil ditambahkan dan disimpan oleh sistem.') ->success(); } }