EMfinanga
1 month ago
291
12
Laravel

combine two query into one

Posted 1 month ago by EMfinanga

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

Please sign in or create an account to participate in this conversation.