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();