F
Filamentβ€’12mo ago
code jam

Update 2 models using a single form? (with transaction)

I have two models, Order & OrderContent. (And a third, Stocks). Order contains the summary of the order and OrderContent will hold multiple rows for each item in the order - typical invoice setup. I want to capture the order and it's content in a single filamentResource using a wizard form, first tab capturing the order and second tab capturing the content (repeater fields). How to save the contents of this form into the two tables using transaction? Also, add validation to OrderContent fields by querying a third table, Stocks? I was thinking of handling it in mutateBeforeCreate(), but I won't be able to perform the transaction. So, I guess I should override the createRecord completely and write my own create function for this resource. And add custom validation for the fields individually using stock availability. Is there a simpler way? Any examples please.. Thank you.
3 Replies
Patrick Boivin
Patrick Boivinβ€’12mo ago
But if you need something completely custom, I think you're on the right track with CreateRecord::create()
Oddman
Oddmanβ€’12mo ago
Where is that createRecord method found? In the exact same scenario. Oh, nevermind, i see - in the create record page πŸ™‚