*/ public static function forSelect(?int $parentId = null, int $level = 0): Collection { $groups = collect([]); foreach (Group::where('parent_id', $parentId)->orderBy('name')->get()->toBase() as $group) { $groups->push(['name' => str_repeat('- ', $level) . $group->name, 'id' => $group->id]); $groups = $groups->merge(static::forSelect($group->id, $level + 1)); } return $groups; } /** * @return Collection */ public static function cacheForSelect(): Collection { return static::collect(static::forSelect()); } }