fixed tests

This commit is contained in:
Denis Duliçi 2021-05-15 10:00:14 +03:00
parent 93a23d9399
commit 43c32b7b58
2 changed files with 13 additions and 9 deletions

View File

@ -52,7 +52,9 @@ class CreateUser extends Job
}
if ($this->request->has('companies')) {
if (request()->isNotInstall()) {
if (app()->runningInConsole() || request()->isInstall()) {
$this->user->companies()->attach($this->request->get('companies'));
} else {
$user = user();
$companies = $user->withoutEvents(function () use ($user) {
@ -62,8 +64,6 @@ class CreateUser extends Job
if ($companies->isNotEmpty()) {
$this->user->companies()->attach($companies->toArray());
}
} else {
$this->user->companies()->attach($this->request->get('companies'));
}
}

View File

@ -53,14 +53,18 @@ class UpdateUser extends Job
}
if ($this->request->has('companies')) {
$user = user();
if (app()->runningInConsole() || request()->isInstall()) {
$this->user->companies()->attach($this->request->get('companies'));
} else {
$user = user();
$companies = $user->withoutEvents(function () use ($user) {
return $user->companies()->whereIn('id', $this->request->get('companies'))->pluck('id');
});
$companies = $user->withoutEvents(function () use ($user) {
return $user->companies()->whereIn('id', $this->request->get('companies'))->pluck('id');
});
if ($companies->isNotEmpty()) {
$this->user->companies()->sync($companies->toArray());
if ($companies->isNotEmpty()) {
$this->user->companies()->sync($companies->toArray());
}
}
}