src/Model/ModelUtil.php
public function findRootParentRecursively(string $parentProperty, string $table, Model $instance, bool $returnInstanceIfNoParent = true)
    {
        if (!$instance || !$instance->{$parentProperty}
            || null === ($parentInstance = $this->findModelInstanceByPk($table, $instance->{$parentProperty}))) {
            return $returnInstanceIfNoParent ? $instance : null;
        }

        return $this->findRootParentRecursively($parentProperty, $table, $parentInstance);
    }
public function findRootParentRecursively(string $parentProperty, string $table, Model $instance, bool $returnInstanceIfNoParent = true)
    {
        if (!$instance || !$instance->{$parentProperty}
            || null === ($parentInstance = $this->findModelInstanceByPk($table, $instance->{$parentProperty}))) {
            return $returnInstanceIfNoParent ? $instance : null;
        }

        return $this->findRootParentRecursively($parentProperty, $table, $parentInstance);
    }
public function findRootParentRecursively ( string $ parentProperty , string $ table , Model $ instance , bool $ returnInstanceIfNoParent = true ) { if ( ! $ instance || ! $ instance -> { $ parentProperty } || null === ( $ parentInstance = $ this -> findModelInstanceByPk ( $ table , $ instance -> { $ parentProperty } ) ) ) { return $ returnInstanceIfNoParent ? $ instance : null ; } return $ this -> findRootParentRecursively ( $ parentProperty , $ table , $ parentInstance ) ; }
Recursively finds the root parent.

@param string $parentProperty
@param string $table
@param Model  $instance
@param bool   $returnInstanceIfNoParent

@return Model
Recursively finds the root parent .