© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
1 reply
HGalih

get new repeater item only filament when editing

I want to decrease user balance everytime they order. This is what I did
    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $user = Auth::user();
        $data['user_id'] = $user->id;
        if(auth()->user()->balance < $data['total_price'])
            throw new \Exception('Insufficient balance');

        foreach ($this->data['paket_bot'] as  &$value) {
            $package = \App\Models\BotPackage::find($value['bot_package_id']);
            $value['expired_at'] = now()->addDays($package->day_count);
            if($value['quantity'] < 1) $value['quantity'] = 1;
            $value['price'] = $package->discounted * $value['quantity'];
        }

        $user->decreaseOrIncreaseBalance(-$data['total_price']);
        return $data;
    }
    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $user = Auth::user();
        $data['user_id'] = $user->id;
        if(auth()->user()->balance < $data['total_price'])
            throw new \Exception('Insufficient balance');

        foreach ($this->data['paket_bot'] as  &$value) {
            $package = \App\Models\BotPackage::find($value['bot_package_id']);
            $value['expired_at'] = now()->addDays($package->day_count);
            if($value['quantity'] < 1) $value['quantity'] = 1;
            $value['price'] = $package->discounted * $value['quantity'];
        }

        $user->decreaseOrIncreaseBalance(-$data['total_price']);
        return $data;
    }


'paket_bot' is a repeater that hold product datas.

The catch is they can also update it (add more product but not delete previous product). And if they do add another product, I need to decrease the balance again. How do I avoid decreasing the user balance for the previous ordered item? (because repeater hold both old and new product data)
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Repeater add new item
FilamentFFilament / ❓┊help
3y ago
Repeater Duplicate queries when adding new item
FilamentFFilament / ❓┊help
2y ago
Filament v2 Repeater can't detect when item deleted
FilamentFFilament / ❓┊help
2y ago
Show item preview when repeater item is collapsed
FilamentFFilament / ❓┊help
2y ago