Repeater-Field should not updated
Hello, if I have a repeater with a many-to-many relationship with a pivot model. Is it possible that if I change the content of a repeater field, a new record will be generated in the relations table and the old one will not be updated? The last part about not updating is particularly causing me problems. Thanks for your help
6 Replies
I'm curious to know more about your use-case. Just reading the description, my first thought is that the repeater is probably not the right tool for the job?
My application is as follows: I would like to prepare monthly invoices for my customers. I have a customer table, an articles table and an invoice_positions pivot table that connects customers with articles. I use the Filament repeater to prepare the billing positions of the monthly invoices. The assignments between articles and customers are saved in the pivot table. However, there should be the opportunity to adapt an article for a customer, e.g. a special price. Then this special price should not overwrite the basic article, but a new article should be created. In the new article, the ID of the basic article is then stored as a foreign key in a base_article_id field so that the origin still remains traceable. I hope I was able to explain it to reasonably understandably.
Which filament-element would be more suitable for this? Or do you have a completely different approach for this problem? I am grateful for every little help.
Thanks, it makes sense. Maybe the repeater is still appropriate for your use-case after all. But I'm not sure if you can accomplish this with
->relationship()
, because it's designed to update the related item directly.One possible solution that comes to mind would be to use a repeater that's not connected to any field or relationship. You could initialize the repeater data manually when the page is loaded, and then add a customized "save" step. Maybe
afterSave()
would be an interesting place to experiment :
https://filamentphp.com/docs/3.x/panels/resources/editing-records#lifecycle-hooksThis seems more appropriate to a relationship manager than a repeater to me.
Thank you very much for your ideas. I'll try both and report back here! π π