effectivePhotoLimit(); if ($limit === null || $limit <= 0) { return; } $newUsed = $eventPackage->used_photos; $thresholds = collect(config('package-limits.photo_thresholds', [])) ->filter(fn (float $value) => $value > 0 && $value < 1) ->sort() ->values(); if ($limit > 0) { $previousRatio = $previousUsed / $limit; $newRatio = $newUsed / $limit; foreach ($thresholds as $threshold) { if ($previousRatio < $threshold && $newRatio >= $threshold) { $this->dispatcher->dispatch(new EventPackagePhotoThresholdReached( $eventPackage, $threshold, $limit, $newUsed, )); } } } if ($newUsed >= $limit && ($previousUsed < $limit)) { $this->dispatcher->dispatch(new EventPackagePhotoLimitReached($eventPackage, $limit)); } } public function recordGuestUsage(EventPackage $eventPackage, int $previousUsed, int $delta = 1): void { $limit = $eventPackage->effectiveGuestLimit(); if ($limit === null || $limit <= 0) { return; } $newUsed = $eventPackage->used_guests; $grace = (int) config('package-limits.guest_grace', 10); $hardLimit = $limit + max(0, $grace); $thresholds = collect(config('package-limits.guest_thresholds', [])) ->filter(fn (float $value) => $value > 0 && $value < 1) ->sort() ->values(); if ($limit > 0) { $previousRatio = $previousUsed / $limit; $newRatio = $newUsed / $limit; foreach ($thresholds as $threshold) { if ($previousRatio < $threshold && $newRatio >= $threshold) { $this->dispatcher->dispatch(new EventPackageGuestThresholdReached( $eventPackage, $threshold, $limit, $newUsed, )); } } } if ($newUsed >= $hardLimit && ($previousUsed < $hardLimit)) { $this->dispatcher->dispatch(new EventPackageGuestLimitReached($eventPackage, $hardLimit)); } } }