feat : section
This commit is contained in:
27
app/Service/ServiceTrait/Admin/SectionTrait.php
Normal file
27
app/Service/ServiceTrait/Admin/SectionTrait.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user