Issue with halt() on beforeSave and a repeater with relationship
So I am working on a Inventory Management System for a client where we have to deal with inventory (product with boxes, batches, etc) and I am having an issue when managing the products added to a sale.
So if I am editing a sale with 3 products and I delete one of them, when I click save I want to reset the stock assigned for those 3 products and after the sale is updated I want to assign the stock again to the 2 products that are left. However, looks like the repeater is doing it's own thing independently and on beforeSave I can only see the 2 products that are left and not the 3 that were originally there.
I have been playing around and I've figured that if I try to get the list of products with $this->record->saleProducts on beforeSave(), the actual sale_products table gets updated so is impossible for me to see if a product has been deleted or not.
I have tried to alter the delete action of the repeater and I can reassing the stock and everything but if the user does not click save later the deleted product shows again and now the inventory does not match the reality.
What am I doing wrong?
Solution:Jump to solution
Completely forgot about this post I made. The solution was to called the booted static method in the model that is used inside the repeater and call the static::deleting method to reset the stock in there:
2 Replies
I am having exactly the same issue. Problem is that Filament is saving the repeater relationship before beforeSave() hook is executed.
Solution
Completely forgot about this post I made. The solution was to called the booted static method in the model that is used inside the repeater and call the static::deleting method to reset the stock in there: