Merge branch 'master' of https://github.com/yanwenwu/catch-admin
This commit is contained in:
commit
da683a3592
@ -94,6 +94,28 @@ class Role extends CatchController
|
|||||||
$role->attach(array_unique($attachIds));
|
$role->attach(array_unique($attachIds));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 更新department
|
||||||
|
$hasDepartmentIds = $role->getDepartments()->column('id');
|
||||||
|
$departmentIds = $request->param('departments');
|
||||||
|
|
||||||
|
// 已存在部门 IDS
|
||||||
|
$existedDepartmentIds = [];
|
||||||
|
foreach ($hasDepartmentIds as $hasDepartmentId) {
|
||||||
|
if (in_array($hasDepartmentId, $departmentIds)) {
|
||||||
|
$existedDepartmentIds[] = $hasDepartmentId;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$attachDepartmentIds = array_diff($departmentIds, $existedDepartmentIds);
|
||||||
|
$detachDepartmentIds = array_diff($hasDepartmentIds, $existedDepartmentIds);
|
||||||
|
|
||||||
|
if (!empty($detachDepartmentIds)) {
|
||||||
|
$role->detachDepartments($detachDepartmentIds);
|
||||||
|
}
|
||||||
|
if (!empty($attachDepartmentIds)) {
|
||||||
|
$role->attachDepartments(array_unique($attachDepartmentIds));
|
||||||
|
}
|
||||||
|
|
||||||
return CatchResponse::success();
|
return CatchResponse::success();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user