A framework-agnostic PHP SDK for managing genealogy data structures compatible with @kcesys/react-genealogy.
composer require kcesys/php-genealogyUse the Builder to transform your raw data (Arrays, Objects, Database Models) into a valid Graph structure.
use KCESYS\Genealogy\Builder;
$users = [
(object)['id' => 1, 'name' => 'Grandpa', 'father_id' => null],
(object)['id' => 2, 'name' => 'Father', 'father_id' => 1],
];
$graph = Builder::from($users)
->mapId(fn($u) => $u->id)
->mapLabel(fn($u) => $u->name)
->mapParents(fn($u) => $u->father_id ? [$u->father_id] : [])
->build();
// Output JSON for React
echo json_encode($graph); You can also build the graph manually using FamilyNode.
use KCESYS\Genealogy\GenealogyGraph;
use KCESYS\Genealogy\FamilyNode;
$graph = new GenealogyGraph();
$node = new FamilyNode('1', ['label' => 'Me']);
$graph->addNode($node);