© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
11 replies
The Huntsman

Mutate form data before create but for delete

    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $data['date_issued'] = date(now());
        $amount = $data['stock_issued'];
        $stock = DB::table('inventories')->where('id', $data['inventory_id'])->value('stock');
        if ($amount > $stock) {
            Notification::make()
                ->warning()
                ->title('You don\'t have enough Stock!!!')
                ->body('Only ' . $stock . ' in inventory.')
                ->send();
            $this->halt();
        } else {
            DB::table('inventories')->where('id', $data['inventory_id'])->update(['stock' => $stock - $amount]);
        }
        return $data;
    }
    protected function mutateFormDataBeforeCreate(array $data): array
    {
        $data['date_issued'] = date(now());
        $amount = $data['stock_issued'];
        $stock = DB::table('inventories')->where('id', $data['inventory_id'])->value('stock');
        if ($amount > $stock) {
            Notification::make()
                ->warning()
                ->title('You don\'t have enough Stock!!!')
                ->body('Only ' . $stock . ' in inventory.')
                ->send();
            $this->halt();
        } else {
            DB::table('inventories')->where('id', $data['inventory_id'])->update(['stock' => $stock - $amount]);
        }
        return $data;
    }


I use the above code to update the inventory when inventory is issued out, I was wondering if there is a function like this but for the delete button so I can undo the inventory update if a record from issued inventory is deleted.
Solution
Yup That works, Thank You.
Jump to solution
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

mutate form data before fill
FilamentFFilament / ❓┊help
3y ago
Mutate Data before Create (calculated column)
FilamentFFilament / ❓┊help
2y ago
Mutate Before Create Function
FilamentFFilament / ❓┊help
3y ago
Very simple mutate data before create. But it is not working
FilamentFFilament / ❓┊help
3y ago