function ($q) { $q->select('id', 'product_id', 'productStock', 'productPurchasePrice', 'productSalePrice'); }]) ->where('business_id', auth()->user()->business_id) ->where('product_type', '!=', 'combo'); if (request('search')) { $productsQuery->where(function ($q) { $q->where('productName', 'like', '%' . request('search') . '%') ->orWhereHas('stocks', function ($stock) { $stock->where('productSalePrice', 'like', '%' . request('search') . '%') ->orWhere('productPurchasePrice', 'like', '%' . request('search') . '%'); }); }); } $stock_reports = $productsQuery ->latest() ->limit($request->per_page ?? 20) ->get(); return view('business::reports.stocks.excel-csv', compact('stock_reports')); } }