// 构建用户显示菜单节点
public function getMenus($pid=0)
{
$menus = self::select(['id','pid','name','route'])->where(['type'=>'GET','status'=>'Y','pid'=>$pid])->with(['SecondMenus'=>function($query){
$query->where(['type'=>'GET','status'=>'Y'])->select(['id','pid','name','route']);
}])->get();
return $menus;
}
// 获取全部节点
public function getAllMenus($pis = 0)
{
$menus = self::select(['id','pid','name','route'])->where(['type'=>'GET','pid'=>$pid])->with(['SecondMenus'=>function($query){
$query->select(['id','pid','name','route']);
}])->get();
return $menus;
}
public function SecondMenus()
{
return $this->hasMany(AdminNode::class,'pid','id');
}
主要自己学习使用, 结合with 和一对多的使用,构建出权限的结构树

被折叠的 条评论
为什么被折叠?



