load('excludeCategories'); if ($coupon->excludeCategories->isEmpty()) { return $next($coupon); } foreach (Cart::items() as $cartItem) { if ($this->inExcludedCategories($coupon, $cartItem)) { throw new InapplicableCouponException; } } return $next($coupon); } private function inExcludedCategories($coupon, $cartItem) { return $coupon->excludeCategories->intersect($cartItem->product->categories)->isNotEmpty(); } }