Repeater inside a relationship manager action
I am trying to implement a repeater inside of a modal form within a relationship manager for products.
My relationship structure is as follows:
Order -> Product -> Attachment -> RevenueLine.
I am trying to add the action to the ProductRelationManager so I can have a link inside the table of products in the order to add new attachments instead of opening the product edit page.
The repeater is nicely shown, and I can create new database records through this repeater
However after I clicked save and reopen the dialog it does not show the data. I can see in the docs that I need to fill the form but how can this be done for the repeater field? Also when I add a new attachment after I created the first few, it tries to delete all the attachments and then reinsert. This is not possible for my structure because every attachment has a relationship with revenueLines so it returns a foreign key constraint error
Solution:Jump to solution
I found it, you indeed need to fill the form with the relationship data manually:
```php
Action::make('attachments')
->icon('heroicon-o-link')
->fillForm(fn (Product $record): array => [...
10 Replies
This is currently my action with the form:
Hey, sorry to bother you, I have not worked yet with repeaters. But I want to know how you are adding the logic for total amount? I mean, I have a order in where I need to show the products and the price of that product, also it can be multiple products too.
What exactly is your scenario? You have an order with multiple products and want to show the price of all products in the order?
Yes exactly, suppose I am choosing a product then the price should show in the total amount which is inside order, similarly if i am choosing multiple products so the amount of all products means whatever i am choosing it should directly show the total amount of that multiple products which is inside the order. Got it I guess?
The products I will choose it should show the amount accordingly if its single then it should show only amount of that single product similarly if its multiple then the amount should calculate and show the total amount of multiple products. Got it?
If you are inside a table of your order and have set up a relation between order and its products, then you can do something like this:
TextColumn::make('total_price')->getStateUsing(fn($record) => $record->products->sum('price'))
This will then create a column in your table with the sum of all products price
Please check this and let me know.
Can you create a sepparete help question? I will respond in there! 🙂
Sure. Okay forget about this large file, sorry about it. But I really need a help with this actually.
So I added this
TextColumn::make('total_price')->getStateUsing(fn($record) => $record->products->sum('price'))
Anything I need to change in migration?
$table->decimal('total_amount', 10, 2)->default(0.00);
basically I have this in my migration file.
Solution
I found it, you indeed need to fill the form with the relationship data manually:
3,