Relationship with a relationship after create?
I need to add some relationship data to a relationships relationship. For example:
Order -> products -> customisations
In a duplicate order function, We have the repeater loading which loads the products relationship, I want to then clone over the customisations relationship. We don't seem to be able to use mutateRelationshipDataBeforeCreating to assign the relationship values.. and theres no record at this state, it's almost like we need an afterCreate function on a repeater relationship?
14 Replies
Just use a custom handler ?
Not qutie that easy. we already. The only way I can see to do this, would be to run on the after method but in doing so it's awfully labersome.
I'm out then ๐
I'll just use after, it's just woefully laboursome really to what i needed to be hehe
That worked ok in the end ๐
Hey @toeknee Exact same scenario, I need to do something after the repeater relationship has been created. How did you manage to do it ?
I jsut used ->after() I think. What is your exact scenario?
I am creating a new purchase, purchase has many payments that is being created with purchase using repeater. Then I need to access the total paid amount i.e sum of amount from multiple payments records and subtract it from total purchase amount to calculate due. My goal is to record this due amount in payments_due table. Using observer hasn't been much help as the payments is not created when purchase created event is fired.
Observers are no good for this scenario.You want to use the after method
GitHub
How to do action after create Filament Resource ยท filamentphp filam...
Package Form builder Package Version v3 How can we help you? i use filament resource for Product Resource , and i want to send newsletter or do anything after record , i see there's ->after ...
I just got an idea while typing this, i can create a due hidden field, then I can use dehydrateStateusing and do my calculations there and customize the creation process to record the due. ? does this sound good ?
you cna do that, but people can manipluate it lowering the due amount.
Add the due amount to the record, and use ->after() to sum and save.
Manipulating due amount is not a concern actually. It's an internal system.
Then that would work ๐
I actuially do that now for internal payroll system ๐
On the repeater i do
I managed to do it like this ๐
And then in createPurchase