Before method in repeater delete action
How can I have like a before method in repeater delete action?
14 Replies
You can call lifecycle hook methods on the action.
Why can't you use the ->after() hook?
nope, it doesnt work in repeater class
can someone help me?
I don't think there is such an option, what are you trying to acheive?
mutate options are here:
https://filamentphp.com/docs/3.x/forms/fields/repeater
You could use a custom deleteAction to preform actions before etc.
I want to calculate the data in other table before or after the repeater record is deleted.
How can I use deleteAction?
Ahh so just add the state to the repeater
->afterStateUpdated()
I tried with
->afterStateUpdated(fn($state) => dd($state))
But the return is the remaining item, not the deleted item.
I need the deleted item id..
What do you mean by “other table”?
for example, I have to update the qty on table stock if one of the goods is deleted in repeater..
I just don’t understand a separate table and form in this context.
Like a table reads from the db via an eloquent query, so how can the table be updated until after the form is submitted and persisted.
I certainly could be misunderstanding though.
here's the simplified schema of my case.
distribution table: id, company
distribution_detail table: distribution_id, goods_id, qty
stock table: goods_id, company_id, qty
goods: id, name
the repeater is the distribution_detail at the distribution form.
Is the repeater not tied to the stock relationship?
Even if it is, deleting an item from the repeater won’t affect the stock until the form is saved.
Which makes sense because you don’t want to affect the stock until the action is persisted.
God bless, I ended solved it with observer..
thanks for your replies before @awcodes and @toeknee
You need to create a custom delete action and disable the origin delete action from the repeater.
like
Repeater::make()...->deletable(false)->extraItemActions([ ... //your custom delete logic here ])
you can delete the Item from repeater like: