From 306c36df85adda0d1abca4bd3f60e001ceaa00e7 Mon Sep 17 00:00:00 2001 From: JaguarJack Date: Wed, 22 Apr 2020 21:29:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E8=A7=92=E8=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- catch/permissions/controller/Role.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/catch/permissions/controller/Role.php b/catch/permissions/controller/Role.php index 969e12d..3213626 100644 --- a/catch/permissions/controller/Role.php +++ b/catch/permissions/controller/Role.php @@ -40,8 +40,9 @@ class Role extends CatchController { $this->role->storeBy($request->param()); - if (!empty($request->param('permissions'))) { - $this->role->attach($request->param('permissions')); + $permissions = $request->param('permissions'); + if (!empty($permissions)) { + $this->role->attach(array_unique($permissions)); } if (!empty($request->param('departments'))) { $this->role->attachDepartments($request->param('departments')); @@ -69,14 +70,14 @@ class Role extends CatchController public function update($id, Request $request): Json { $this->role->updateBy($id, $request->param()); - $role = $this->role->findBy($id); - $role->detach(); - if (!empty($request->param('permissions'))) { - $role->attach($request->param('permissions')); + $permissions = $request->param('permissions'); + if (!empty($permissions)) { + $this->role->attach(array_unique($permissions)); } + if (!empty($request->param('departments'))) { $role->detachDepartments(); $role->attachDepartments($request->param('departments'));