Skip to content

Commit

Permalink
#11 debug the menu permission
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Sep 6, 2024
1 parent 2dfff3c commit 41a9960
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
43 changes: 41 additions & 2 deletions src/Http/Controllers/Api/V2/Admin/User/PermissionController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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())
{
Expand Down Expand Up @@ -179,20 +198,40 @@ 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)
{
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'))
Expand Down
5 changes: 2 additions & 3 deletions src/Http/Controllers/Api/V2/Admin/User/RoleController.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

namespace NexaMerchant\Apis\Http\Controllers\Api\V2\Admin\User;

use App\Models\Permission;
use App\Models\Role;
use NexaMerchant\Apis\Models\Role;
use NexaMerchant\Apis\Models\Permission;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Validator;
Expand Down

0 comments on commit 41a9960

Please sign in to comment.