agent_id) ->whereHas('agentProductItem', function ($query) { return $query->whereHas('product', function ($query) { return $query->where('stock', '<=', 0)->orWhere('status', '<>', ProductStatus::ON_SALE); }); }) ->orWhere('stock', '<=', 0) ->update(['status' => ProductStatus::SOLD_OUT]); } }