Skip to content

Instantly share code, notes, and snippets.

@jaynarayan89
Created August 21, 2019 14:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaynarayan89/563b9b5943761f330d62ea8d7728c1fb to your computer and use it in GitHub Desktop.
Save jaynarayan89/563b9b5943761f330d62ea8d7728c1fb to your computer and use it in GitHub Desktop.
closure table tree query
public function getTree($root, $level = 3)
{
$nodes = DB::select(
'
SELECT
members.id,
members.first_name,
members.leg_side,
members.parent_id
FROM members
JOIN binary_plan_tree_paths ON members.id=binary_plan_tree_paths.descendant
WHERE binary_plan_tree_paths.ancestor=?
AND binary_plan_tree_paths.depth < ?',
[$root,$level]
);
return $nodes;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment