27 lines
682 B
PHP
27 lines
682 B
PHP
<?php
|
|
|
|
namespace App\Service\ServiceTrait\Admin;
|
|
|
|
trait SectionTrait
|
|
{
|
|
/**
|
|
* 递归生成合适的数据
|
|
* @param array $allMenuList
|
|
* @param int $parentId
|
|
* @return array
|
|
*/
|
|
protected function getDbList(array $allMenuList, int $parentId = 0): array
|
|
{
|
|
$menuList = [];
|
|
foreach ($allMenuList as $menu) {
|
|
if ($menu['pid'] == $parentId) {
|
|
$children = $this->getDbList($allMenuList, (int)$menu['id']);
|
|
if (!empty($children)) {
|
|
$menu['children'] = $children;
|
|
}
|
|
$menuList[] = $menu;
|
|
}
|
|
}
|
|
return $menuList;
|
|
}
|
|
} |