fixed user api enable / disable endpoint issue.
This commit is contained in:
parent
8f349ee9c4
commit
d264769a1d
@ -89,26 +89,28 @@ class UpdateUser extends Job implements ShouldUpdate
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Can't unassigned company, The company must be assigned at least one user.
|
// Can't unassigned company, The company must be assigned at least one user.
|
||||||
$companies = (array) $this->request->get('companies', []);
|
if ($this->request->has('companies')) {
|
||||||
$user_companies = $this->model->companies()->pluck('id')->toArray();
|
$companies = (array) $this->request->get('companies', []);
|
||||||
|
$user_companies = $this->model->companies()->pluck('id')->toArray();
|
||||||
|
|
||||||
$company_diff = array_diff($user_companies, $companies);
|
$company_diff = array_diff($user_companies, $companies);
|
||||||
|
|
||||||
if ($company_diff) {
|
if ($company_diff) {
|
||||||
$errors = [];
|
$errors = [];
|
||||||
|
|
||||||
foreach ($company_diff as $company_id) {
|
foreach ($company_diff as $company_id) {
|
||||||
$company = Company::withCount('users')->find($company_id);
|
$company = Company::withCount('users')->find($company_id);
|
||||||
|
|
||||||
if ($company->users_count < 2) {
|
if ($company->users_count < 2) {
|
||||||
$errors[] = trans('auth.error.unassigned', ['company' => $company->name]);
|
$errors[] = trans('auth.error.unassigned', ['company' => $company->name]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if ($errors) {
|
if ($errors) {
|
||||||
$message = implode('\n', $errors);
|
$message = implode('\n', $errors);
|
||||||
|
|
||||||
throw new \Exception($message);
|
throw new \Exception($message);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user