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;
    }


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.
Was this page helpful?