效果图:
查询代码:
use app\model\Menu;
function getMenuList(string $uid)
{
$list = Menu::where('pid', $uid)->select();
foreach ($list as $val) {
$val['children'] = getMenuList($val->uid);
}
return $list;
}
function getMenuBelong(string $uid)
{
$has = [];
$list = Menu::where('pid', $uid)->select();
foreach ($list as $val) {
$has[] = $val->id;
$next = getMenuBelong($val->uid);
$has = array_merge($has, $next);
}
return $has;
}
模型
<?php
namespace app\model;
use think\Model;
class Menu extends Model
{
protected $schema = [
'id' => 'int',
'menu_title' => 'string',
'menu_type' => 'int',
'cate_uid' => 'string',
'use_cate_uid' => 'int',
'open_tag' => 'int',
'uid' => 'string',
'pid' => 'string',
'order_sort' => 'int',
'create_time' => 'int',
];
protected $autoWriteTimestamp = 'create_time';
}