Fixes for client limits on hosted

This commit is contained in:
David Bomba 2022-03-06 14:41:08 +11:00
parent b4303d0b57
commit c65948d10c
2 changed files with 6 additions and 4 deletions

View File

@ -76,7 +76,7 @@ class StoreClientRequest extends Request
]; ];
if (auth()->user()->company()->account->isFreeHostedClient()) { if (auth()->user()->company()->account->isFreeHostedClient()) {
$rules['hosted_clients'] = new CanStoreClientsRule($this->company_id); $rules['id'] = new CanStoreClientsRule(auth()->user()->company()->id);
} }
$rules['number'] = ['nullable',Rule::unique('clients')->where('company_id', auth()->user()->company()->id)]; $rules['number'] = ['nullable',Rule::unique('clients')->where('company_id', auth()->user()->company()->id)];

View File

@ -21,6 +21,8 @@ class CanStoreClientsRule implements Rule
{ {
public $company_id; public $company_id;
public $company;
public function __construct($company_id) public function __construct($company_id)
{ {
$this->company_id = $company_id; $this->company_id = $company_id;
@ -33,9 +35,9 @@ class CanStoreClientsRule implements Rule
*/ */
public function passes($attribute, $value) public function passes($attribute, $value)
{ {
$company = Company::find($this->company_id); $this->company = Company::find($this->company_id);
return $company->clients->count() < $company->account->hosted_client_count; return $this->company->clients()->count() < $this->company->account->hosted_client_count;
} }
/** /**
@ -43,6 +45,6 @@ class CanStoreClientsRule implements Rule
*/ */
public function message() public function message()
{ {
return ctrans('texts.limit_clients', ['count' => $company->account->hosted_client_count]); return ctrans('texts.limit_clients', ['count' => $this->company->account->hosted_client_count]);
} }
} }