v2board/app/Services/PlanService.php
2022-07-08 12:07:36 +08:00

24 lines
475 B
PHP

<?php
namespace App\Services;
use App\Models\Plan;
use App\Models\User;
class PlanService
{
public $plan;
public function __construct(int $planId)
{
$this->plan = Plan::lockForUpdate()->find($planId);
}
public function haveCapacity(): bool
{
if ($this->plan->capacity_limit === NULL) return true;
$count = User::where('plan_id', $this->plan->plan_id)->count();
return $this->plan->capacity_limit - $count;
}
}