Laravel设置递归函数来获取父代及其子代

时间:2019-04-04 09:52:28

标签: php laravel laravel-5.7 laravel-5.8

我正在系统中创建角色管理模块。我在配置文件中获取模块权限。数组看起来像:

"user_management" => array:3 [▼
"display_name" => "Users"
"permissions" => []
"child" => array:2 [▼
  "user_internal_management" => array:3 [▼
    "display_name" => "Roam Users"
    "permissions" => array:5 [▼
      "browse_user_internal" => "Browse Roam  Users"
      "view_user_internal" => "View Roam Users"
      "add_user_internal" => "Add Roam User"
      "edit_user_internal" => "Edit Roam User"
      "delete_user_internal" => "Delete Roam User"
    ]
    "child" => []
  ]
  "user_corporate_management" => array:3 [▼
    "display_name" => "Client Users"
    "permissions" => array:5 [▼
      "browse_user_corporate" => "Browse Client Users"
      "view_user_corporate" => "View Client Users"
      "add_user_corporate" => "Add Client User"
      "edit_user_corporate" => "Edit Client User"
      "delete_user_corporate" => "Delete Client User"
    ]
    "child" => []
  ]
]
]

user_managementuser_internal_management & user_corporate_management的父级,而user_managementpermission的子级 创建新角色时我想要什么,我只想显示登录用户在添加表单上具有的特定权限。

因此对于create函数,我得到了所有ID(已登录用户的权限)和parent> child > child表的ID。 我想安排这个ID的数组,定义如上。 array:8 [▼ 0 => 1 1 => 68 2 => 69 3 => 70 4 => 71 5 => 72 6 => 73 7 => 74 ]

我得到了权限ID的数组,如;

-----------------------------
| id  | desc      | state    |
-----------------------------
| 1   | desc 1    | Complete |
| 2   | desc 2    | Open     |
| ... | ...       | ...      |
-----------------------------

我的桌子看起来像enter image description here

我该怎么做??

0 个答案:

没有答案