From 41a9960d25403197cfd881cedb26d58376de0315 Mon Sep 17 00:00:00 2001 From: Steve <34465153+xxl4@users.noreply.github.com> Date: Fri, 6 Sep 2024 16:37:26 +0800 Subject: [PATCH] #11 debug the menu permission --- .../V2/Admin/User/PermissionController.php | 43 ++++++++++++++++++- .../Api/V2/Admin/User/RoleController.php | 5 +-- 2 files changed, 43 insertions(+), 5 deletions(-) diff --git a/src/Http/Controllers/Api/V2/Admin/User/PermissionController.php b/src/Http/Controllers/Api/V2/Admin/User/PermissionController.php index b372937..6b25e5f 100644 --- a/src/Http/Controllers/Api/V2/Admin/User/PermissionController.php +++ b/src/Http/Controllers/Api/V2/Admin/User/PermissionController.php @@ -2,7 +2,7 @@ namespace NexaMerchant\Apis\Http\Controllers\Api\V2\Admin\User; -use App\Models\Permission; +use NexaMerchant\Apis\Models\Permission; use Illuminate\Http\Request; use Illuminate\Support\Facades\Validator; use stdClass; @@ -96,6 +96,25 @@ public function update(Request $request) 'sort' => 'nullable|integer', 'status' => 'nullable|integer', 'type' => 'required|integer', + ],[ + 'id.required' => 'id is required', + 'id.integer' => 'id must be an integer', + 'id.min' => 'id must be greater than 0', + 'parent_id.integer' => 'parent_id must be an integer', + 'title.required' => 'title is required', + 'title.string' => 'title must be a string', + 'name.string' => 'name must be a string', + 'redirect.string' => 'redirect must be a string', + 'icon.string' => 'icon must be a string', + 'path.string' => 'path must be a string', + 'component.string' => 'component must be a string', + 'permission.required' => 'permission is required', + 'permission.string' => 'permission must be a string', + 'affix.integer' => 'affix must be an integer', + 'sort.integer' => 'sort must be an integer', + 'status.integer' => 'status must be an integer', + 'type.required' => 'type is required', + 'type.integer' => 'type must be an integer', ]); if ($validator->fails()) { @@ -179,13 +198,31 @@ public function create(Request $request) 'sort' => 'nullable|integer', 'status' => 'nullable|integer', 'type' => 'required|integer', + ], + [ + 'parent_id.integer' => 'parent_id must be an integer', + 'title.required' => 'title is required', + 'title.string' => 'title must be a string', + 'name.string' => 'name must be a string', + 'redirect.string' => 'redirect must be a string', + 'icon.string' => 'icon must be a string', + 'component.string' => 'component must be a string', + 'path.string' => 'path must be a string', + 'permission.required' => 'permission is required', + 'permission.string' => 'permission must be a string', + 'permission.unique' => 'permission already exists', + 'affix.integer' => 'affix must be an integer', + 'sort.integer' => 'sort must be an integer', + 'status.integer' => 'status must be an integer', + 'type.required' => 'type is required', + 'type.integer' => 'type must be an integer', ]); if ($validator->fails()) { return $this->fails($validator->errors()); } $permission = new Permission(); - if ($request->filled('parent_id')) + if ($request->filled('parent_id') && $request->parent_id!="0") { $parent = Permission::find($request->parent_id); if (!$parent) @@ -193,6 +230,8 @@ public function create(Request $request) return $this->fails('parent not found'); } $permission->parent_id = $request->parent_id; + }else{ + $permission->parent_id = 0; } $permission->title = $request->title; if ($request->filled('name')) diff --git a/src/Http/Controllers/Api/V2/Admin/User/RoleController.php b/src/Http/Controllers/Api/V2/Admin/User/RoleController.php index 670dab3..987116e 100644 --- a/src/Http/Controllers/Api/V2/Admin/User/RoleController.php +++ b/src/Http/Controllers/Api/V2/Admin/User/RoleController.php @@ -1,9 +1,8 @@