Попробуйте это:
$total_quantity = Item::find(1) // getting the Item
->orders() // entering the relationship
->with('items') // eager loading related data
->where('status', '=', 'received') // constraining the relationship
->get() // getting the results: Collection of Order
->sum('pivot.quantity'); // sum the pivot field to return a single value.
Стратегия здесь состоит в том, чтобы найти нужные Item
, чтобы затем получить соответствующие Order
s для этого Item
, который имеет статус 'received'
, чтобы, наконец, sum
атрибут pivot, чтобы получить один значение.
Это должно работать.