app/Services/ChartService.php
public function descendants(Individual $individual, int $generations): Collection
    {
        $descendants = new Collection([$individual]);

        if ($generations > 0) {
            foreach ($individual->spouseFamilies() as $family) {
                foreach ($family->children() as $child) {
                    $descendants = $descendants->merge($this->descendants($child, $generations - 1));
                }
            }
        }

        return $descendants;
    }
public function descendants(Individual $individual, int $generations): Collection
    {
        $descendants = new Collection([$individual]);

        if ($generations > 0) {
            foreach ($individual->spouseFamilies() as $family) {
                foreach ($family->children() as $child) {
                    $descendants = $descendants->merge($this->descendants($child, $generations - 1));
                }
            }
        }

        return $descendants;
    }
public function descendants ( Individual $ individual , int $ generations ) : Collection { $ descendants = new Collection ( [ $ individual ] ) ; if ( $ generations > 0 ) { foreach ( $ individual -> spouseFamilies ( ) as $ family ) { foreach ( $ family -> children ( ) as $ child ) { $ descendants = $ descendants -> merge ( $ this -> descendants ( $ child , $ generations - 1 ) ) ; } } } return $ descendants ; }
Find the descendants of an individual.

@param Individual $individual  Start with this individual
@param int        $generations Fetch this number of generations

@return Collection
@return Individual[]
Find the descendants of an individual .