© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
5 replies
ericmp #2

Count relationship quantity via pivot

models:
ProductPack
Product

ProductPackPivot (n n table):
pivot extra field -> product_quantity

for each ProductPack i want to know how many products it has. at the moment im doing it like this, but this only counts the relationships:
ProductPack::query()
    ->withCount('products')
    ...
ProductPack::query()
    ->withCount('products')
    ...


and i need to go to the pivot, and get the
product_quantity
product_quantity
field instead of counting the relation

im kinda lost on how to achieve it.

example:
lets say i have a product pack that has 2 products:
4 waters
2 forks

the product pack has 2 products, but really has 4+2 products, so i need to get 6 instead of 2
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Relationship with pivot
FilamentFFilament / ❓┊help
3y ago
Pivot Select using Relationship
FilamentFFilament / ❓┊help
2w ago
Display count of relationship in table column where pivot value = something
FilamentFFilament / ❓┊help
3y ago
Repeater not saving pivot relationship
FilamentFFilament / ❓┊help
2y ago