Change logic for adding user

This commit is contained in:
David Bomba 2021-11-06 10:40:38 +11:00
parent c91ab24d49
commit 27db04515a

View File

@ -12,6 +12,7 @@
namespace App\Http\ValidationRules\Ninja;
use App\Models\CompanyUser;
use App\Models\User;
use Illuminate\Contracts\Validation\Rule;
/**
@ -32,12 +33,22 @@ class CanAddUserRule implements Rule
public function passes($attribute, $value)
{
$count = CompanyUser::query()
->with('user')
// $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('user_id')
->count();
->select('users.id')
->count();
return $count < auth()->user()->company()->account->num_users;
//return auth()->user()->company()->account->users->count() < auth()->user()->company()->account->num_users;