where('is_active', 1) ->groupStart() ->whereIn('LOWER(name)', $lower) ->orWhereIn('LOWER(slug)', $lower) ->groupEnd() ->orderBy('priority', 'ASC') // highest priority first ->findAll(); } public function getRouteByNameOrSlug(string $key): ?string { $row = $this->where('is_active', 1) ->groupStart() ->where('LOWER(name)', strtolower($key)) ->orWhere('LOWER(slug)', strtolower($key)) ->groupEnd() ->first(); return $row['dashboard_route'] ?? null; } public function getRoles() { return $this->findAll(); } /** Map role names -> role IDs */ public function getIdsByNames(array $names): array { $names = array_values(array_filter(array_map('strval', $names))); if (empty($names)) return []; $lower = array_values(array_unique(array_map('strtolower', $names))); $builder = $this->select('id') ->groupStart() ->whereIn('LOWER(name)', $lower); if ($this->db->fieldExists('slug', $this->table)) { $builder->orWhereIn('LOWER(slug)', $lower); } $ids = $builder->groupEnd()->findColumn('id'); return array_map('intval', $ids ?? []); } }