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
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:Jump to 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....7 Replies
What does: products.pivot.quantity show?
nothing
and what about: products.pivot
but if i remove the pivot here's what i getWhat does that mean? Remove pivot from where?
from her
Tables\Columns\TextColumn::make('products'),
if i remove it i get the json data
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.Got it i will try it out and hope it works
I didn't see with pivot() in the docs
Thanks brother 🫡