From 99cfb9bc9ba31f4312d74b0b5ca2216b49c517c9 Mon Sep 17 00:00:00 2001 From: xiaochong0302 Date: Sat, 19 Dec 2020 15:38:57 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=A7=92=E8=89=B2routes?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=A1=AB=E5=85=85=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Admin/Services/Role.php | 11 +++++++---- app/Models/Role.php | 2 ++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/Http/Admin/Services/Role.php b/app/Http/Admin/Services/Role.php index 82fde39a..86bade39 100644 --- a/app/Http/Admin/Services/Role.php +++ b/app/Http/Admin/Services/Role.php @@ -61,8 +61,11 @@ class Role extends Service $data['name'] = $validator->checkName($post['name']); $data['summary'] = $validator->checkSummary($post['summary']); - $data['routes'] = $validator->checkRoutes($post['routes']); - $data['routes'] = $this->handleRoutes($data['routes']); + + if (isset($post['routes'])) { + $data['routes'] = $validator->checkRoutes($post['routes']); + $data['routes'] = $this->handleRoutes($data['routes']); + } $role->update($data); @@ -114,9 +117,9 @@ class Role extends Service * @param array $routes * @return array */ - protected function handleRoutes($routes) + protected function handleRoutes(array $routes) { - if (empty($routes)) { + if (count($routes) == 0) { return []; } diff --git a/app/Models/Role.php b/app/Models/Role.php index 827a368a..a30b573b 100644 --- a/app/Models/Role.php +++ b/app/Models/Role.php @@ -105,6 +105,8 @@ class Role extends Model { if (is_array($this->routes) && !empty($this->routes)) { $this->routes = kg_json_encode($this->routes); + } else { + $this->routes = ''; } $this->create_time = time();