F
Filament7mo ago
Toku

How can i Access the data in pivot table in a table filed

Hi i am trying to get the data in the pivot table and i don't know what i am doing wrong i read docs but i didn't see anything like my problem
here's my code Tables\Columns\TextColumn::make('products.pivot.quantity'), for some reason this doesn't return anything but if i remove the pivot here's what i get {"id":1, "name":"orange juice", "description":"orange juice 100%", "picture":"01HYJHYD9MQW9JGV365REH72X7.jpg", "quantity":6, "price":5, "calories":200, "sub_category_id":1, "pivot":{ "cart_id":1, "product_id":1, "quantity":3} }, i want to get the quantity value in the pivot table and i want to show it in my table like what product does the user have in his / her cart and the amount of that product
Solution:
Dot notation is for relationships. You can either try ->withPivot() method on your relation as mentioned in the docs (https://filamentphp.com/docs/3.x/panels/resources/relation-managers#listing-with-pivot-attributes) or using getStateUsing() on the column to access that object....
Jump to solution
7 Replies
toeknee
toeknee7mo ago
What does: products.pivot.quantity show?
Toku
TokuOP7mo ago
nothing
No description
toeknee
toeknee7mo ago
and what about: products.pivot
Dennis Koch
Dennis Koch7mo ago
but if i remove the pivot here's what i get
What does that mean? Remove pivot from where?
Toku
TokuOP7mo ago
from her Tables\Columns\TextColumn::make('products'), if i remove it i get the json data
Solution
Dennis Koch
Dennis Koch7mo ago
Dot notation is for relationships. You can either try ->withPivot() method on your relation as mentioned in the docs (https://filamentphp.com/docs/3.x/panels/resources/relation-managers#listing-with-pivot-attributes) or using getStateUsing() on the column to access that object.
Toku
TokuOP7mo ago
Got it i will try it out and hope it works I didn't see with pivot() in the docs Thanks brother 🫡
Want results from more Discord servers?
Add your server