Вы можете объединить эти запросы и получить разницу
SELECT
sum(
IF(a.to_warehouse_id = '2', b.transfer_quantity, 0)
) - sum(
IF(a.from_warehouse_id = '2', b.transfer_quantity, 0)
) as total
FROM
inventory_transfers AS a
JOIN inventory_transfer_details AS b ON a.id = b.inventory_transfer_id
WHERE
a.status = "approved"
AND b.inventory_or_composite_id = '1'
В конструкторе запросов laravel этот запрос может выглядеть как
DB::table('inventory_transfers as a')
->select(DB::raw('sum(IF(a.to_warehouse_id = '2', b.transfer_quantity, 0)) - sum(IF(a.from_warehouse_id = '2', b.transfer_quantity, 0)) as total'))
->join('inventory_transfer_details as b', DB::raw('a.id'), '=', DB::raw('b.inventory_transfer_id'))
->where([
['a.status', '=', 'approved']
['b.inventory_or_composite_id', '=', 1]
])
->get()