F
Filamentβ€’3mo ago
nowak

Displaying related pivot record details on table

I have a GroupOrderResource, that has a HasMany relationship with UserOrder, and UserOrder has a ManyToMany relationship with Products with a pivot table storing details on product_id, product_name, and quantity. Now, I need to show a summary of products ordered, like this:
Product_1 x 8
Product_2 x 5
Product_1 x 8
Product_2 x 5
For each GroupOrder. Traditionally in a spreadsheet, this would be done by having a big cell containing all products, but I was wondering if there is filament feature that is built for displaying this in smarter way? It is important that this information is visible directly on the table view, as this will be used as a "packing slip". I think maybe stacking a repeater column, which would generate a column for each product related to the GroupOrder could be a solution, but maybe I am over thinking this?
6 Replies
Solution
nowak
nowakβ€’3mo ago
Thanks! I think this would get the job done. Is there a way to remove duplicates from the list? And I assume I can do something like this to build my list items:
'concat(product_name, \' \', quantity)'
'concat(product_name, \' \', quantity)'
Or is that not possible?
awcodes
awcodesβ€’3mo ago
Yea. You can use formatStateUsing() to make it whatever you need. So in your case just loop the values and format them into a new array that is returned .
nowak
nowakβ€’3mo ago
Ahh awesome! I was about to write that I could also write a method in my GroupOrder model that produces an attribute, with the list I need, without duplicates, and with the concatenation, and just add that to TextColumn::make().
awcodes
awcodesβ€’3mo ago
For duplication look into either the collect() laravel helper or the Arr laravel class. As long as an array representation of the state is returned you can do what ever you need to in order to format its output.
nowak
nowakβ€’3mo ago
Thanks a lot! I think I can solve the problem now πŸ™‚