You are assuming that you are getting one instance, but you are getting a collection.
Change ->get() to ->first()
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
i want to have one foreach loop in blade view after combine this query
$balanceQty=CashSales::with('items')
->select('item_id',DB::raw('sum(quantity) as tqty'))
->whereIn('l_type',['credit_sale','cash_sale'])
->groupby('item_id')
->get();
$balanceQty1=CashSales::with('items')
->select('item_id',DB::raw('sum(quantity) as tqty1'))
->whereIn('l_type',['open balance','purchase'])
->groupby('item_id')
->get();
$data=$balanceQty->merge($balanceQty1);
$balanceQtyOut=(int)$balanceQty1->tqty1-(int)$balanceQty->tqty;
i get this error
Property [tqty1] does not exist on this collection instance
someone can assist me
Once you switch to first() you will not get collections but single instances of CashSales. Then you do not need $data=$balanceQty->merge($balanceQty1);. If you want those two instances to be in array or collection then you can do
$data = [$balanceQty, $balanceQty1];
Please or to participate in this conversation.