join('access', 'access.menu_id', '=', 'menu.id') ->select('menu.*', 'access.role_id') ->where($where) ->orderBy('listorder', 'asc') ->get()); if($menu) { foreach($menu as $row) { $row['deep'] = $pad; if($PermissionsMenu = self::getPermissionsMenu($role_id, $row['id'], $pad+1)) { $row['child'] = $PermissionsMenu; } $res[] = $row; } } return $res; } }