PlanService.php 472 B

1234567891011121314151617181920212223
  1. <?php
  2. namespace App\Services;
  3. use App\Models\Plan;
  4. use App\Models\User;
  5. class PlanService
  6. {
  7. public $plan;
  8. public function __construct(int $planId)
  9. {
  10. $this->plan = Plan::lockForUpdate()->find($planId);
  11. }
  12. public function haveCapacity(): bool
  13. {
  14. if ($this->plan->capacity_limit === 0) return true;
  15. $count = User::where('plan_id', $this->plan->plan_id)->count();
  16. return $this->plan->capacity_limit - $count;
  17. }
  18. }