Duplicate the row for many to many relationship in Model A List page
instead of showing ModelBs relationships with "," separating them, how can i tell filament to duplicate the whole row with the other relationship value.
i tried custom column, it works fine if i kept it in the end where i can end the row as html, but is there a better way that i can achieve the above
7 Replies
are you using ReplicateAction or something?
replicate will create another record, what i am looking to achieve is the the following, instead of
i want the following
so it's just a matter of displaying
what i tried to use is to create a custom column and call getrecord to add them manually, it's a workaround that's messy so i just discarded it in the end, but i wonder if there's an easy way to acheive it
sounds like you want a belongstomany relationship?
with a relation manager?
you shouldnt put duplicate rows in your table
i already have many to many relationship and the relationship is displayed like above. no issues with that
usually i shouldn't, but what if i want to following
product 1 | Store 1 | price in store 1 |
_
product 1 | store 2 | price in store 2 |
otherwise, the above will show llike this
product 1 | store 1 , store 2 | price store 1 , price store 2
in the end i ended up doing the following just to make it better
then i would get
product 1 | store 1 | price 1
| store 2 | price 2
----------------------------
but ofc it would've been better to duplicate the row
right but this isnt a products table anymore
this is a productStore table
each row is a ProductStore pivot model
true, i didn't try pivot model method, let me check if it works
so i did the following which didn't work
also i tried the following which also didn't work
with Tables\Columns\TextColumn ::make('product_services.id')
not sure if im missing something, but in both cases they show record1,record2 in the same row
I think what Dan is saying is that you need another/different table. You're basically trying to add a bunch of mini ProductStore tables inside your Products table which isn't currently possible.
One solution would be to add a ProductStoreRelationManager to your Products Resource and then when you click to view a Product you'd see the relation manager and the product's stores and prices.
The other solution is just change the resource to reference your ProductStore pivot model. The only issue here is you'd see product's name duplicated for each store. And if you sorted the table they wouldn't be grouped anymore.
If you need to see the stores/prices in that table then you'd have to do your own custom column like you were doing right now.
But I believe that grouping is coming in v3.