优化角色

This commit is contained in:
JaguarJack 2020-04-22 21:29:13 +08:00
parent b71bba6a1e
commit 306c36df85

View File

@ -40,8 +40,9 @@ class Role extends CatchController
{ {
$this->role->storeBy($request->param()); $this->role->storeBy($request->param());
if (!empty($request->param('permissions'))) { $permissions = $request->param('permissions');
$this->role->attach($request->param('permissions')); if (!empty($permissions)) {
$this->role->attach(array_unique($permissions));
} }
if (!empty($request->param('departments'))) { if (!empty($request->param('departments'))) {
$this->role->attachDepartments($request->param('departments')); $this->role->attachDepartments($request->param('departments'));
@ -69,14 +70,14 @@ class Role extends CatchController
public function update($id, Request $request): Json public function update($id, Request $request): Json
{ {
$this->role->updateBy($id, $request->param()); $this->role->updateBy($id, $request->param());
$role = $this->role->findBy($id); $role = $this->role->findBy($id);
$role->detach(); $role->detach();
if (!empty($request->param('permissions'))) { $permissions = $request->param('permissions');
$role->attach($request->param('permissions')); if (!empty($permissions)) {
$this->role->attach(array_unique($permissions));
} }
if (!empty($request->param('departments'))) { if (!empty($request->param('departments'))) {
$role->detachDepartments(); $role->detachDepartments();
$role->attachDepartments($request->param('departments')); $role->attachDepartments($request->param('departments'));