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.
|
||||
$companies = (array) $this->request->get('companies', []);
|
||||
$user_companies = $this->model->companies()->pluck('id')->toArray();
|
||||
if ($this->request->has('companies')) {
|
||||
$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) {
|
||||
$errors = [];
|
||||
if ($company_diff) {
|
||||
$errors = [];
|
||||
|
||||
foreach ($company_diff as $company_id) {
|
||||
$company = Company::withCount('users')->find($company_id);
|
||||
foreach ($company_diff as $company_id) {
|
||||
$company = Company::withCount('users')->find($company_id);
|
||||
|
||||
if ($company->users_count < 2) {
|
||||
$errors[] = trans('auth.error.unassigned', ['company' => $company->name]);
|
||||
if ($company->users_count < 2) {
|
||||
$errors[] = trans('auth.error.unassigned', ['company' => $company->name]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($errors) {
|
||||
$message = implode('\n', $errors);
|
||||
if ($errors) {
|
||||
$message = implode('\n', $errors);
|
||||
|
||||
throw new \Exception($message);
|
||||
throw new \Exception($message);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user