F
Filamentβ€’6mo ago
S1efan

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
Patrick Boivin
Patrick Boivinβ€’6mo ago
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?
S1efan
S1efanOPβ€’6mo ago
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.
Patrick Boivin
Patrick Boivinβ€’6mo ago
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.
Patrick Boivin
Patrick Boivinβ€’6mo ago
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-hooks
awcodes
awcodesβ€’6mo ago
This seems more appropriate to a relationship manager than a repeater to me.
S1efan
S1efanOPβ€’6mo ago
Thank you very much for your ideas. I'll try both and report back here! πŸ™ πŸ™ƒ
Want results from more Discord servers?
Add your server