diff --git a/app/Http/Controllers/PreviewController.php b/app/Http/Controllers/PreviewController.php index 19489a4b7d..153f76a656 100644 --- a/app/Http/Controllers/PreviewController.php +++ b/app/Http/Controllers/PreviewController.php @@ -217,8 +217,6 @@ class PreviewController extends BaseController if(!$request->has('entity_id')) $entity_obj->service()->fillDefaults()->save(); - // $entity_obj->load('client.contacts','client.company'); - App::forgetInstance('translator'); $t = app('translator'); App::setLocale($entity_obj->client->locale()); diff --git a/app/Http/ValidationRules/Ninja/CanAddUserRule.php b/app/Http/ValidationRules/Ninja/CanAddUserRule.php index 1c85687bf3..4e88125507 100644 --- a/app/Http/ValidationRules/Ninja/CanAddUserRule.php +++ b/app/Http/ValidationRules/Ninja/CanAddUserRule.php @@ -33,25 +33,14 @@ class CanAddUserRule implements Rule public function passes($attribute, $value) { - // $count = CompanyUser::query() - // ->with('user') - // ->where('account_id', auth()->user()->account_id) - // ->distinct() - // ->select('user_id') - // ->count(); - - - $count = User::query() - ->with(['company_user' => function ($query){ - return $query->whereNull('company_user.deleted_at'); - }]) - ->where('account_id', auth()->user()->account_id) - ->distinct() - ->select('users.id') - ->count(); + $count = CompanyUser::query() + ->where('account_id', auth()->user()->account_id) + ->whereNull('deleted_at') + ->distinct() + ->count('user_id'); return $count < auth()->user()->company()->account->num_users; - //return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users; + } /** diff --git a/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php b/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php index 45bf5ec7f3..db7291dc19 100644 --- a/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php +++ b/app/Http/ValidationRules/Ninja/CanRestoreUserRule.php @@ -33,17 +33,15 @@ class CanRestoreUserRule implements Rule public function passes($attribute, $value) { - $count = User::query() - ->with(['company_user' => function ($query){ - return $query->whereNull('company_user.deleted_at'); - }]) - ->where('account_id', 1) - ->distinct() - ->select('users.id') - ->count(); + $count = CompanyUser::query() + ->where('account_id', auth()->user()->account_id) + ->whereNull('deleted_at') + ->distinct() + ->count('user_id'); + return $count < auth()->user()->company()->account->num_users; - //return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users; + } /**