1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Merge pull request #6939 from turbo124/v5-develop

Change logic for adding user
This commit is contained in:
David Bomba 2021-11-06 10:42:13 +11:00 committed by GitHub
commit 52a49f1b18
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

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;